Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core-js 3 missing .js extension when 'type': 'module' #12378

Closed
1 task
bytestream opened this issue Nov 20, 2020 · 7 comments · Fixed by #10862
Closed
1 task

core-js 3 missing .js extension when 'type': 'module' #12378

bytestream opened this issue Nov 20, 2020 · 7 comments · Fixed by #10862
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@bytestream
Copy link

Bug 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

@babel-bot
Copy link
Collaborator

Hey @bytestream! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

Fixed by #10862

@bytestream
Copy link
Author

Thank you for the fast reply @nicolo-ribaudo

Is there a workaround until that's merged?

@nicolo-ribaudo
Copy link
Member

You could try using https://github.com/tleunen/babel-plugin-module-resolver to add the .js extension to core-js imports.

@pongstylin
Copy link

pongstylin commented Nov 28, 2020

I've tried to use the recommended workaround without success. Has anybody else had success with it? Here's my .babelrc file. It is effective at changing other resolve paths when I change what I match against, so the plugin does seem to be doing stuff. It just doesn't seem to catch the problematic imports.

{
  "plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "^core-js/modules/(.+)$": "core-js/modules/\\1.js"
        }
      }
    ]
  ]
}

@bytestream
Copy link
Author

No it didn't work for me either. I removed the code that required corejs polyfill 😅

@babel babel deleted a comment from RamboHunterJb Nov 28, 2020
@eugeneoshepkov
Copy link

eugeneoshepkov commented Nov 29, 2020

I'm having the same issue in my configuration. babel-plugin-module-resolver didn't help since most of node_modules packages are not transpiled, making that alias config above useless

@babel babel deleted a comment from RamboHunterJb Dec 4, 2020
@babel babel deleted a comment from RamboHunterJb Dec 6, 2020
@babel babel deleted a comment from RamboHunterJb Dec 10, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Mar 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants