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.

[Bug]: true `ignoreBrowserslistConfig` but reading `.browserslistrc`

See original GitHub issue

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

$ strace -f -e file -o file.log babel --config-file ./babel.config.json example.mjs

Configuration file name

babel.config.json

Configuration

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "debug": true,
        "ignoreBrowserslistConfig": true,
        "targets": {
          "chrome": "92"
        }
      }
    ]
  ]
}

Current and expected behavior

Actual

$ grep -F .browserslist file.log && echo FAIL || echo OK
... access("/path/to/cwd/browserslist", F_OK) = -1 ENOENT (No such file or directory)
... access("/path/to/cwd/.browserslistrc", F_OK) = -1 ENOENT (No such file or directory)
... access("/path/to/cwd/browserslist-stats.json", F_OK) = -1 ENOENT (No such file or directory)
... access("/path/to/browserslist-stats.json", F_OK) = -1 ENOENT (No such file or directory)
... access("/path/browserslist-stats.json", F_OK) = -1 ENOENT (No such file or directory)
... access("/browserslist-stats.json", F_OK) = -1 ENOENT (No such file or directory)
FAIL

Expected

$ grep -F .browserslist file.log && echo FAIL || echo OK
OK

Environment

@babel/preset-env: ^7.15.6 => 7.15.6

Possible solution

No response

Additional context

Not a real world use case

Just try to analyze filesystem footprint, to solve another config problem by another build tool .

Found babel have this footprint, even set ignoreBrowserslistConfig to false.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
JLHwungcommented, Sep 27, 2021

The current behaviour is expected:

  • preset-env does not load .browserslistrc as instructed by ignoreBrowserslistConfig: true. Actually since you have specified targets, you can safely remove ignoreBrowserslistConfig.
  • @babel/core loads .browserslistrc because the top level targets option is not provided. Note that @babel/core is unaware of preset-env, so it tries to load the browserslist config, in order to determine a global targets information that can be respected by all plugins/presets.

In your case, if you migrate targets in preset-env to top level, Babel will not load browserslistrc.

{
  "targets": {
    "chrome": "92"
  },
  "presets": [
    [
      "@babel/preset-env",
      {
        "debug": true,
      }
    ]
  ]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

browserslistrc being ignored #2332 - rails/webpacker - GitHub
Webpacker seems to be ignoring browserslist. ... browserlist settings, reading all the docs we could find, but it just doesn't seem to work....
Read more >
Babel with babel-preset-env seems to ignore browserslist config
But, the problem is that Babel seems to ignore the browserslist key. The same is true if I use a .browserslistrc file containing:...
Read more >
babel/preset-env
By default @babel/preset-env will use browserslist config sources unless either the targets or ignoreBrowserslistConfig options are set.
Read more >
browserslist | Yarn - Package Manager
The config to share target browsers and Node.js versions between different ... Improved unknown region and unknown feature error (by Alexander Chabin).
Read more >
@babel/preset-env - npm
Browserslist config will be ignored if: 1) targets.browsers was specified 2) or with ignoreBrowserslistConfig: true option (see more): ...
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