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
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 22e7d25.
@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
Still erroring on:
all IE <= 11 issue not present with
2.5.1
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.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:
…
https://webpack.js.org/guides/code-splitting-async/#promise-polyfill
On Thu, Jun 22, 2017 at 6:25 PM Réda Housni Alaoui <
***@***.***> wrote:
> I am currently using webpack 2.6.1.
> I still need a promise polyfill because System.import still leads to ES6
> Promise creation.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#4916 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AANWcnGig7rx4mEjgPaNk5RKd70A0yKKks5sGpWGgaJpZM4NjETV>
> .
>
I don’t want to bother my original Webpack config, so here is a workaround: