question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better error handling for `include` and `exclude` options when option is not an array

See original GitHub issue

Bug 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:open
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolo-ribaudocommented, May 14, 2020

Opening a PR in the babel/website repository is enough 🙏

1reaction
nicolo-ribaudocommented, May 13, 2020

It’s yours!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ruby: Is there an opposite of include? for Ruby Arrays?
ActiveSupport adds the exclude? method to Array , Hash , and String . This is not pure Ruby, but is used by a...
Read more >
9 Best Practices to Handle Java Exceptions - Stackify
Handling Java exceptions isn't easy, especially for beginners. Read this post to understand exceptions and best practices for using them.
Read more >
Options - Babel.js
This option exists so that users who cannot use source maps can get vaguely useful error line numbers, but it is only a...
Read more >
$project (aggregation) — MongoDB Manual
This restriction does not apply to conditionally exclusion of a field using the ... MongoDB also provides $addFields to add new fields to...
Read more >
@rollup/plugin-typescript - npm
If a type error is detected, the Rollup build is aborted when this option is set to true. files , include , exclude....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found