Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Error: Can't resolve '@babel/runtime-corejs3/helpers/asyncToGenerator' #16238

@nyngwang

Description

@nyngwang

💻

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

export const myAsync = async () => {
}

Configuration file name

babel.config.js

Configuration

export default {
  plugins: [
    '@babel/plugin-transform-runtime',
    [
      'polyfill-corejs3', {
        method: 'usage-global',
        // version: jsonPackage.dependencies['core-js'],
        // proposals: true,
      },
    ],
  ],
  presets: [
    '@babel/preset-env',
  ],
}

Current and expected behavior

I got the following error:

Error: Can't resolve '@babel/runtime-corejs3/helpers/asyncToGenerator'

I expect that there will be no error since @babel/plugin-transform-runtime has the default option corejs: false which means @babel/runtime will be used, not @babel/runtime-corejs3.

Environment

  System:
    OS: macOS 14.2
  Binaries:
    Node: 20.9.0 - ~/miniforge3/envs/main/bin/node
    Yarn: 3.6.1 - ~/miniforge3/envs/main/bin/yarn
    npm: 10.3.0 - ~/miniforge3/envs/main/bin/npm
  npmPackages:
    @babel/core: ^7.23.7 => 7.23.7 
    @babel/plugin-transform-runtime: ^7.23.7 => 7.23.9 
    @babel/preset-env: ^7.23.9 => 7.23.9 
    @babel/preset-react: ^7.23.3 => 7.23.3 
    @babel/runtime: ^7.23.8 => 7.23.9 
    babel-loader: ^9.1.3 => 9.1.3 
    webpack: ^5.89.0 => 5.89.0

package.json

  "devDependencies": {
    "@babel/core": "^7.23.7",
    "@babel/plugin-transform-runtime": "^7.23.7",
    "@babel/preset-env": "^7.23.9",
    "@babel/preset-react": "^7.23.3",
    "babel-loader": "^9.1.3",
    "html-webpack-plugin": "^5.6.0",
    "webpack": "^5.89.0",
    "webpack-cli": "^5.1.4",
    "webpack-dev-server": "^4.15.1"
  },
  "dependencies": {
    "@babel/runtime": "^7.23.8",
    "core-js": "^3.35.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }

Possible solution

No response

Additional context

In short, I have a js file that defines an async function and I want to transpile it using the following combination:

  1. @babel/plugin-transform-runtime with default option corejs: false
  2. babel-plugin-polyfill-corejs3with option method: 'usage-global'
  3. @babel/runtime as the runtime dependency

I only install @babel/runtime not @babel/runtime-corejs3 because I want to transpile those helpers myself instead of using those pure version ones provided in @babel/runtime-corejs3. But from the error above it seems that babel-plugin-polyfill-corejs3 is still insisting on referencing things in @babel/runtime-corejs3. How to fix it?

With the old way to setup usage-global, I got no error:

  1. @babel/preset-env with option useBuiltIns: 'usage' corejs: 3.xx
  2. @babel/plugin-transform-runtime without default option corejs: false
  3. @babel/runtime as the runtime dependency

This is because there will be no usage of @babel/runtime-corejs3 in the output bundle.

So the first approach is not equivalent to the second one, and I suspect that this might be a bug: I have specified the method as usage-global... so why would that @babel/runtime-corejs3 appear here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions