Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
JMarkoski opened this issue May 13, 2020 · 6 comments · May be fixed by #11567
Open
1 task done

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

JMarkoski opened this issue May 13, 2020 · 6 comments · May be fixed by #11567

Comments

@JMarkoski
Copy link
Contributor

JMarkoski commented May 13, 2020

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

const expandIncludesAndExcludes = (
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:

const selectedPlugins = plugins.map(plugin =>

@babel-bot
Copy link
Collaborator

Hey @JMarkoski! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

It's yours!

@JMarkoski
Copy link
Contributor Author

JMarkoski commented May 14, 2020

@nicolo-ribaudo I found another, somewhat related issue, so my question is whether to open another separate issue (maybe for better documentation of what is fixed) or to fix the problem in this one. The issue is as follows:

The docs about include (https://babeljs.io/docs/en/babel-preset-env#include say that plugins prefixed with plugin- are valid, which is false. The only valid plugin names are those prefixed with @babel/, @babel/plugin-, babel-, babel-plugin-. The problem is with the regex normalizing polyfill names here:

plugin.replace(/^(@babel\/|babel-)(plugin-)?/, "");
. So, either the docs should be updated, or the regex fixed to include those plugin names too.

EDIT: PR for this issue: babel/website#2250

@nicolo-ribaudo
Copy link
Member

Let's update the docs and keep the regexp as-is.

@JMarkoski
Copy link
Contributor Author

@nicolo-ribaudo Should I update the docs in this issue or should I file a separate one?

@nicolo-ribaudo
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants