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

@babel/preset-env doesn't read .browserslistrc file (still works using targets option) #12721

Closed
gremo opened this issue Jan 30, 2021 · 6 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@gremo
Copy link

gremo commented Jan 30, 2021

It seems that @babel/preset-env doesn't read the .browserslistrc anymore.

FIle .browserslistrc:

defaults
not ie 11
not ie_mob 11

When I run npm run babel -- assets/js/app.js with the following test file:

document.addEventListener('DOMContentLoaded', () => {
  // DOM ready
  [1, 2, 3].forEach(n => console.log(n));
});

Output uses the targets is empty:

babel "assets/js/app.js"

@babel/preset-env: DEBUG option

Using targets:
{}

However, It still works if I use the targets option in .babelrc.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: .babelrc
{
  "presets": [
    ["@babel/preset-env", {
      "corejs": 3,
      "useBuiltIns": "usage",
      "bugfixes": true,
      "modules": false,
      "debug": true
    }]
  ]
}

Environment

  System:
    OS: Windows 10 10.0.19042
  Binaries:
    Node: 12.18.4 - C:\Program Files\nodejs\node.EXE       
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    @babel/cli: ^7.12.10 => 7.12.10
    @babel/core: ^7.12.10 => 7.12.10
    @babel/preset-env: ^7.12.11 => 7.12.11
    babel-eslint: ^10.1.0 => 10.1.0
    eslint: ^7.18.0 => 7.18.0
  • Babel version(s): 7.12.10 (@babel/core 7.12.10)
  • Node/npm version: v12.18.4
  • OS: Windows 10 x64
  • How you are using Babel: CLI
@babel-bot
Copy link
Collaborator

Hey @gremo! 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

The problem is that for backward compatibility reasons, if you don't specify a targets option, Babel will tell to browserslist "Hey, defaults means 'transform everything' instead of your usual 'defaults' browsers".

This is tracked by #9962, and it will be fixed by #12616 (we might merge that PR soon, but the fix will only work starting from Babel 8).

@gremo
Copy link
Author

gremo commented Feb 2, 2021

Thanks @nicolo-ribaudo, so what's the proposed solution/workaround? Do you know which 7.x.x version introduced the problem?

@nicolo-ribaudo
Copy link
Member

This problem has been present since babel-preset-env 1.x.
As a workaround, you can copy your browser's list query into your Babel config.

@gremo
Copy link
Author

gremo commented Feb 2, 2021

@nicolo-ribaudo sorry for bother you again but I'm pretty sure that some older project of mine works without problem.

Is the problem only related to the defaults keyword be present?

@nicolo-ribaudo
Copy link
Member

Yes, it's "default" that means "every possible browser version" when Babel reads it from the browserslistrc file.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants