Skip to content

webpack 2.6.0 can't find variable: Promise on require async #4916

@rogeriochaves

Description

@rogeriochaves

Do you want to request a feature or report a bug?

What is the current behavior?

Having ReferenceError: Can't find variable: Promise when using require(['dep'], callback)

If the current behavior is a bug, please provide the steps to reproduce.

So, I'm using karma to run tests on phantomjs with webpack, and phantomjs doesn't have native promises. So, this is why I have this in my webpack.config (also, for older browsers):

...
new webpack.ProvidePlugin({
  Promise: 'es6-promise-promise'
}),
...

Then, on my code, I could do something like this, and everything worked fine until [email protected] (and under, in fact, since 1.x this worked fine):

console.log('promise', Promise);
require(['left-pad'], function (leftpad) {
  // ...
});

But then, simply by upgrading to [email protected], I get the ReferenceError: Can't find variable: Promise error now.

I believe this is because webpack uses promises to load the chunks, and somehow stopped replacing variables from ProvidePlugin on its own boilerplate.

What is the expected behavior?

Promises should work when defined on ProvidePlugin, even if it is webpack generated code, right?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

macOS, but also happened on ubuntu. Node 6.9. Webpack 2.6.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions