@babel/plugin-transform-runtime causes "Promise is undefined" in IE11
See original GitHub issueBug Report
- I would like to work on a fix!
Current behavior My project couldn’t run in IE11 because it encountered “Promise is undefined” when opened. Although webpack is configured to include polyfills when needed. When I commented out @babel/plugin-transform-runtime (so it is no longer used in the webpack config) the project could open in IE11 without any errors.
Input Code The relevant part of the webpack.config where the babel-loader is configured is:
{
test: /(\.(t|j)s(x?))$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
cacheDirectory: true,
babelrc: false,
plugins: [ "@babel/plugin-transform-runtime" ], // when commented out, the project can run in IE11
presets: [
[
"@babel/preset-env",
{
modules: false,
targets: {
browsers: ["last 2 versions", "ie >= 11"]
},
useBuiltIns: 'usage',
corejs: '3',
}
],
"@babel/preset-typescript",
"@babel/preset-react",
]
}
}
]
}
Expected behavior I expect the plugin @babel/plugin-transform-runtime to not cause issues in IE11 and to use the polyfill for Promise.
Environment
System:
OS: Windows 10 10.0.18362
Binaries:
Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
npmPackages:
@babel/core: ^7.9.0 => 7.9.0
@babel/plugin-transform-runtime: ^7.9.0 => 7.9.0
@babel/preset-env: ^7.9.0 => 7.9.0
@babel/preset-react: ^7.9.1 => 7.9.1
@babel/preset-typescript: ^7.9.0 => 7.9.0
babel-loader: ^8.1.0 => 8.1.0
eslint: ^6.8.0 => 6.8.0
webpack: ^4.42.0 => 4.42.0
Possible Solution
Additional context Add any other context about the problem here. Or a screenshot if applicable
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Promise is undefined in IE11 using babel-polyfill
As the title says, even I'd like to use babel-polyfill to allow me to use promises in my code, but I get that...
Read more >babel/preset-env
babel/preset-env` is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, ...
Read more >babel-loader - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >babel-loader - npm
Some files in my node_modules are not transpiled for IE 11 ... NOTE: You must run npm install -D @babel/plugin-transform-runtime to include ...
Read more >axios SharePoint error in IE 11 but not Chrome
When I use axios with SharePoint, it successfully works in Chrome but not in IE 11. The error is 'Promise' is undefined.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You are using
@babel/plugin-transform-runtime
and@babel/preset-env
incorrectly. In this case, you probably have some code that doesn’t explicitly usePromise
s but uses them indirectly and only later in the code when you usePromise
s directly, theusage
plugin frompreset-env
injects globally polluting polyfill forPromise
, but this doesn’t catch the case where you use them indirectly. Eg. if you useasync
functions, babel uses a helper calledasyncToGenerator
that internally usesPromise
s. And if you didn’t use anyPromise
s explicitely before this code, it will fail, because there is no polyfill for it included. For more thorough answer see my answer here: https://github.com/babel/babel/issues/9853#issuecomment-619587386According to Babel’s maintainer,
useBuiltIns
from@babel/preset-env
and@babel/plugin-transform-runtime
are mutually exclusive. This is extremely unclear in the documentation; in fact, in the very first note made in@babel/plugin-transform-runtime
’s docs, it even implies that you should combine it with@babel/preset-env
’suseBuiltIns
if you want global polyfills usingcore-js@3
, even thoughtransform-runtime
has no problems usingcore-js-pure@3
if you configure it to do so.When you configure
@babel/plugin-transform-runtime
without options, it injects dependencies on@babel/runtime
, which contains no ponyfills, making all this even more confusing. Then there is the fact thattransform-runtime
’s documentation sections for optionspolyfill
anduseBuiltIns
claim that they are always turned on, without any description as to what they might do. So all we have to go off is @nicolo-ribaudo’s comment saying thatuseBuiltIns
and@babel/plugin-transform-runtime
can’t be used together. Personally, I use bothpreset-env
andtransform-runtime
, but withuseBuiltIns
andcorejs
set to false, and I just injectcore-js
globally. This way I ensure that all polyfills are available for bundled dependencies that don’t get run through Babel, which often expect things likePromise
.