-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Bug Report: babel-preset-env feature-detection error with dynamic import() statements. #7402
Copy link
Copy link
Closed
Labels
outdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: preset-env
Description
Bug Report:
When using babel-preset-env with useBuiltIns: 'usage' and webpack's dynamic imports (e.g. import('my-module').then(...)) -- along with @babel/plugin-syntax-dynamic-import -- feature-detection fails to include es6.promise, which is required for the code to work on IE11.
Input Code
import('my-module');Compiled input code:
__webpack_require__.e/* import() */(2).then(__webpack_require__.bind(null, 155));Elsewhere in the Webpack runtime:
/******/ __webpack_require__.e = function requireEnsure(chunkId) {
/******/ ...
/******/ // setup Promise in chunk cache
/******/ var promise = new Promise(function(resolve, reject) {
/******/ installedChunkData = installedChunks[chunkId] = [resolve, reject];
/******/ });
/******/ installedChunkData[2] = promise;Babel/Babylon Configuration (.babelrc, package.json, cli command)
{
plugins: ['@babel/plugin-syntax-dynamic-import'],
presets: [
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'usage',
},
],
],
}Expected Behavior
Using targets:
{
"ie": "11"
}
Using modules transform: false
Using polyfills with `usage` option:
[/path/to/my/file.js] Added following polyfill:
es6.promise { "ie":"11" }No errors in IE 11.
Current Behavior
Using targets:
{
"ie": "11"
}
Using modules transform: false
Using polyfills with `usage` option:
[/path/to/my/file.js] Based on your code and targets, none were added.IE11 error: 'Promise' is undefined
Possible Solution
Not sure the ideal fix -- is this a bug in babel-loader, or @babel/preset-env, or @babel/plugin-syntax-dynamic-import, or even webpack? In the meantime, a workaround is to add either of the following in the input JS file:
const p = new Promise();or
import 'core-js/modules/es6.promise';Your Environment
| software | version(s) |
|---|---|
| Babel | 7.0.0-beta.40 |
| webpack | 3.11.0 |
| node | 8.9.4 |
| npm | 5.6.0 |
| yarn | 1.3.2 |
| Operating System | macOS 10.13.3 |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
outdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: preset-env