Invalid warning for not declaring 'corejs' option when using 'useBuiltIns': 'false'
See original GitHub issueBug Report
- I would like to work on a fix!
Current Behavior
When using @babel/preset-env
and setting useBuiltIns: 'false'
and not declaring a corejs
option, the following warning occurs:
WARNING: We noticed you’re using the
useBuiltIns
option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via thecorejs
option.\n" + You should also be sure that the version you pass to thecorejs
option matches the version specified in yourpackage.json
’sdependencies
section. If it doesn’t, you need to run one of the following commands: npm install --save core-js@2 npm install --save core-js@3 yarn add core-js@2 yarn add core-js@3
First, I don’t know if this should be considered a bug, because the problem occurs only when setting the useBuiltIns
option to the string 'false'
and not false
. But if you set it accidentaly to a string value I think It should behave the same as when setting it to a boolean
one.
Expected behavior/code The warning should not occur.
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
babel.config.js
{
presets: [
"@babel/env",
{
useBuiltIns: "false"
}
]
}
Environment
- Babel version: 7.9.0
- Babel preset-env version: 7.9.0
- Node/npm version: 10.17.0
- OS: Ubuntu 18.04.3 LTS
- Monorepo: [e.g. yes/no/Lerna]
- How you are using Babel: [loader]
Possible Solution
Upon inspecting the @babel/preset-env
source code, in the file normalize-options.js
in the function normalizeCoreJSOption
the following check is used
if (useBuiltIns && corejs === undefined) {
Using a more thorough check for useBuiltIns
will fix the warning.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
@JLHwung Yes, I will submit a PR. Also, the same thing should be done with https://github.com/babel/babel/blob/94447135c75a19da867f2e6a8906ce0a7e8f1ed4/packages/babel-preset-env/src/normalize-options.js#L171
I will add a fix for that in the PR as well. Thanks.
We should throw an error about
"false"
not being a valid value instead.