-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Copy link
Labels
Has PRoutdatedA 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 issue
Description
Bug Report
Current Behavior
$ node --experimental-modules dist/example.mjs
(node:5693) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/esm/default_resolve.js:79
let url = moduleWrapResolve(specifier, parentURL);
^
Error: Cannot find module /path/to/example/node_modules/core-js/modules/es.array.iterator imported from /path/to/example/dist/example.mjs
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:79:13)
at Loader.resolve (internal/modules/esm/loader.js:73:33)
at Loader.getModuleJob (internal/modules/esm/loader.js:152:40)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:43:40)
at link (internal/modules/esm/module_job.js:42:36) {
code: 'ERR_MODULE_NOT_FOUND'
}Input Code
src/example.mjs (source code)
for (const x of [1, 2, 3]) {
console.log(x);
}dist/example.mjs (generated code)
import "core-js/modules/es.array.iterator";
for (const x of [1, 2, 3]) {
console.log(x);
}Expected behavior/code
node --experimental-modules dist/example.mjs
(node:5717) ExperimentalWarning: The ESM module loader is experimental.
1
2
3Babel Configuration (.babelrc, package.json, cli command)
[
"@babel/preset-env",
{
"targets": {
"node": "8.5.0"
},
"useBuiltIns": "usage",
"corejs": 3,
"modules": false
}
]Environment
- Babel version(s): 7.6.4
- Node/npm version: Node v12.11.1/npm 6.11.3
- OS: Ubuntu 18.04
- Monorepo: no
- How you are using Babel: cli
Possible Solution
Could you add .js extension when importing polyfill?
import "core-js/modules/es.array.iterator.js"; // needs ".js"
for (const x of [1, 2, 3]) {
console.log(x);
}Now, it will work properly!
$ node --experimental-modules dist/example.mjs
(node:5705) ExperimentalWarning: The ESM module loader is experimental.
1
2
3Additional context/Screenshots
As of Node.js v12, extension requires on import syntax.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Has PRoutdatedA 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 issue