💻
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:
@babel/plugin-transform-runtime with default option corejs: false
babel-plugin-polyfill-corejs3with option method: 'usage-global'
@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:
@babel/preset-env with option useBuiltIns: 'usage' corejs: 3.xx
@babel/plugin-transform-runtime without default option corejs: false
@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?
💻
How are you using Babel?
babel-loader (webpack)
Input code
Configuration file name
babel.config.js
Configuration
Current and expected behavior
I got the following error:
I expect that there will be no error since
@babel/plugin-transform-runtimehas the default optioncorejs: falsewhich means@babel/runtimewill be used, not@babel/runtime-corejs3.Environment
package.json
Possible solution
No response
Additional context
In short, I have a js file that defines an
asyncfunction and I want to transpile it using the following combination:@babel/plugin-transform-runtimewith default optioncorejs: falsebabel-plugin-polyfill-corejs3with optionmethod: 'usage-global'@babel/runtimeas the runtime dependencyI only install
@babel/runtimenot@babel/runtime-corejs3because I want to transpile those helpers myself instead of using thosepureversion ones provided in@babel/runtime-corejs3. But from the error above it seems thatbabel-plugin-polyfill-corejs3is 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:@babel/preset-envwith optionuseBuiltIns: 'usage'corejs: 3.xx@babel/plugin-transform-runtimewithout default optioncorejs: false@babel/runtimeas the runtime dependencyThis is because there will be no usage of
@babel/runtime-corejs3in 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?