webpack: webpack 2.6.0 can't find variable: Promise on require async
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 webpack@2.5.1
(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 webpack@2.6.0
, 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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 36
- Comments: 23 (2 by maintainers)
Commits related to this issue
- Use Promise only when chunk load is triggered don't use it in initialisation fixes #4916 — committed to webpack/webpack by sokra 7 years ago
- Use Promise only when chunk load is triggered don't use it in initialisation fixes #4916 — committed to webpack/webpack by sokra 7 years ago
- Use Promise only when chunk load is triggered don't use it in initialisation fixes #4916 — committed to webpack/webpack by sokra 7 years ago
- Adding Core-JS as dependency Needed for testing only, as webpack 2.6 has a known bug polyfilling promises: https://github.com/webpack/webpack/issues/4916 — committed to leeDav/buildit by leeDav 7 years ago
@sokra Will there be a bugfix release? It seems to have broken quite a lot of builds.
Still have the problem on webpack 2.6.1. Someone else?
Part of my config:
And error is inside the manifest.js
I don’t want to bother my original Webpack config, so here is a workaround:
Actually what I do is have this in my html in the head:
window.Promise||document.write(‘<script src=" https://cdn.polyfill.io/v2/polyfill.min.js"></script>’);
That polyfills everything for any browser that doesn’t have Promise. That includes all of these features: https://polyfill.io/v2/docs/features/ Even though babel has already transformed all of those to safe es5 production code.
So I don’t have any polyfill in my app itself. I don’t force every modern browser to download that. Only the old browsers have to pay the price of that extra fetch.
https://polyfill.io/v2/docs/
On Thu, Jun 22, 2017 at 6:28 PM Chris Sattinger crucialfelix@gmail.com wrote:
The 2.6.1 version seems to fix it. All calls to
Promise
are now done inside a function which gets called at a later time. The first thing I have on my entry file isimport 'core-js';
which provides thePromise
polyfill.Hm… facing a similar issue (in IE 11) with possibly the same cause, even without any asynchronous loading.
Seems that the generated
webpackBootstrap
(defineswebpackJsonp
) code includes a line like this:This line was / is not present using webpack 2.5.x.
Looks to be introduced in 22e7d254ee27e68569ea9718632accc870f52002.
Still erroring on:
all IE <= 11 issue not present with
2.5.1
Then yes, you do need a polyfill. See https://webpack.js.org/guides/code-splitting-async/#promise-polyfill
On Thu, Jun 22, 2017 at 6:25 PM Réda Housni Alaoui notifications@github.com wrote:
It was a mistake in 2.6.0 where a Promise was used in the bootstrap code that loads your app. So this was being called before any code (your app) that has babel or other polyfills applied to it. It was fixed with 2.6.1
Is it normal to be forced to add the Promise polyfill ourselves to make webpack work on IE 11?
thanks!
Experiencing same issue here. In our case the error it’s coming from manifest js:
ReferenceError: Can't find variable: Promise at http://127.0.0.1:42069/unit-manifest-6eed6c926e1a80d7a48c.js:40
.