core-js 3 missing .js extension when 'type': 'module'
See original GitHub issueBug Report
- I would like to work on a fix!
Current behavior
'type': 'module'
is used in package.json
and when corejs: 3
is specified in babel.config.js
webpack complains about missing .js
extension despite it existing in src/page.js
. If I comment out corejs: 3
then the error goes away.
ERROR in ./src/page.js 1:0-37
Module not found: Error: Can't resolve 'core-js/modules/es.weak-set' in '/home/kieran/PhpstormProjects/babel-test/src'
Did you mean 'es.weak-set.js'?
BREAKING CHANGE: The request 'core-js/modules/es.weak-set' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
I would be incredibly grateful if someone could put me out my misery.
Input Code
https://github.com/bytestream/babel-test
Expected behavior
I expect the code to transpile when using corejs 3.
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
babel.config.js
module.exports = {
presets: [
[
'@babel/preset-env',
{
'useBuiltIns': 'entry',
'corejs': 3, // <--- problematic line
}
]
],
plugins: [
// Don't allow polyfills to pollute global namespace.
'@babel/plugin-transform-runtime',
// Support for the experimental syntax 'classPrivateProperties'
'@babel/plugin-proposal-class-properties',
// Support for the experimental syntax 'classPrivateMethods'
'@babel/plugin-proposal-private-methods',
]
};
Environment
$ npx envinfo --preset babel
System:
OS: Linux 4.9 Debian GNU/Linux 9 (stretch) 9 (stretch)
Binaries:
Node: 12.19.0 - /usr/bin/node
Yarn: 1.22.4 - /usr/bin/yarn
npm: 6.14.8 - /usr/bin/npm
npmPackages:
@babel/core: ^7.12.3 => 7.12.3
@babel/plugin-proposal-class-properties: ^7.12.1 => 7.12.1
@babel/plugin-proposal-private-methods: ^7.12.1 => 7.12.1
@babel/plugin-transform-runtime: ^7.12.1 => 7.12.1
@babel/preset-env: ^7.12.1 => 7.12.1
@babel/runtime-corejs3: ^7.12.5 => 7.12.5
babel-loader: ^8.2.1 => 8.2.1
webpack: ^5.6.0 => 5.6.0
Possible Solution
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Typescript import are missing the .js extension when it ...
Is there something I am missing that is not adding the right extension on the imports? Why would TypeScript randomly change your imports?...
Read more >Node.js v19.3.0 Documentation
See assert.throws() for more details. The following, for instance, will throw the TypeError because there is no matching error type in the assertion ......
Read more >Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >Understanding ES6 Modules - SitePoint
Where are Modules in JavaScript? Anyone starting web development a few years ago would have been shocked to discover there was no concept...
Read more >babel/preset-env
Enable transformation of ES module syntax to another module type. ... Built-ins (both for core-js@2 and core-js@3, such as es.map , es.set ...
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 FreeTop 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
Top GitHub Comments
You could try using https://github.com/tleunen/babel-plugin-module-resolver to add the
.js
extension tocore-js
imports.I’m having the same issue in my configuration.
babel-plugin-module-resolver
didn’t help since most ofnode_modules
packages are not transpiled, making that alias config above useless