Better error handling for `include` and `exclude` options when option is not an array
See original GitHub issueBug Report
- I would like to work on a fix!
Current Behavior
When setting the exclude
option on @babel/preset-env
to a string that represents a plugin (with intention to exclude that plugin) babel throws non-descriptive error
plugins.map is not a function
Moreover, if we provide anything other than array for the options exclude
and include
, the same error will be thrown, that relates to the way the https://github.com/babel/babel/blob/9a52019019527be8c179ea7c9025fa2355f16170/packages/babel-preset-env/src/normalize-options.js#L78 function handles the input.
Expected behavior/code The expected behavior is to throw a more descriptive error about invalid options provided and maybe to accept valid strings that map to plugins.
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
babel.config.js
module.exports = {
presets: [
[
"@babel/env",
{
useBuiltIns: "entry",
targets: "> 0.01%",
corejs: 3,
exclude: "transform-regenerator",
},
],
],
};
Environment
System:
OS: Linux 4.15 Ubuntu 18.04.4 LTS (Bionic Beaver)
Binaries:
Node: 10.19.0 - /usr/bin/node
Yarn: 1.22.4 - /usr/bin/yarn
npm: 6.13.4 - /usr/bin/npm
npmPackages:
@babel/cli: ^7.8.4 => 7.8.4
@babel/core: ^7.8.7 => 7.8.7
@babel/plugin-transform-modules-amd: ^7.8.3 => 7.8.3
@babel/plugin-transform-modules-commonjs: ^7.8.3 => 7.8.3
@babel/plugin-transform-runtime: ^7.9.0 => 7.9.0
@babel/preset-env: ^7.9.5 => 7.9.5
@babel/runtime: ^7.9.2 => 7.9.2
@babel/runtime-corejs3: ^7.9.2 => 7.9.2
Possible Solution
Normalize and validate the input before checking here: https://github.com/babel/babel/blob/9a52019019527be8c179ea7c9025fa2355f16170/packages/babel-preset-env/src/normalize-options.js#L85
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Opening a PR in the
babel/website
repository is enough 🙏It’s yours!