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.

Set `modules: false` by default on babel-preset-env

See original GitHub issue

I’m submitting a feature request

Webpack Version: >= 2.x

Babel Loader Version: 7.1.2

Current behavior:

I need to manually disable the modules feature of Babel like this:

test: /\.js$/,
use: {
    loader: 'babel-loader',
    options: {
        presets: ['env', { modules: false }]
    }
}

To let webpack use its own ESM system.

Expected/desired behavior:

For webpack 2.x and higher, babel-loader can detect automatically that we don’t want to use modules.

Sean said I had to mention loaderContext.version = 2 as a way to detect the new webpack version.

  • What is the motivation / use case for changing the behavior?

Many people don’t know this, and especially people who upgraded from webpack 1.x to >2.x often don’t have this enabled (seen this a lot personally).

One problem with this is that it is a breaking change (or at least potentially), but at the long term I think it’s worth it. One less configuration option for most people.

Open question: is there a valid use-case where you want to have modules on true in webpack 2?

cc’ing @hzoo and @TheLarkInn because I know you talked about this a few minutes ago with eachother 🥇

Related: #519

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:15
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
hzoocommented, Oct 27, 2017

https://github.com/babel/babel-loader/pull/485/files does a lot of it already although it’s hardcoded (and we are going to move to scoped packages so it should support @babel/preset-env too)

It’s possible others may disagree. Also I would add the dynamic import syntax on by default too

6reactions
hzoocommented, Oct 27, 2017

Also related is https://github.com/babel/babel-loader/pull/485 and #477 (issue)

Personally I’d rather just make it default, and even warn if they are using with webpack v1 to upgrade. No reason to not do it as long as there’s a way out if you need to

Totally fine with making a major version bump

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/preset-env
By default @babel/preset-env will use browserslist config sources unless either the targets or ... Setting this to false will preserve ES modules.
Read more >
what does the "modules:auto" means in @babel/preset-env ...
According to that PR: The default auto will automatically select false if ES6 module syntax is already supported by the caller, or "commonjs" ......
Read more >
babel-preset-env-modules
A babel preset configured for minimal compiled output in environements that support ESM (but not limited to), with polyfill support.
Read more >
Top 5 babel-preset-env Code Examples
default (null, { targets: { browsers: ['last 2 versions', 'ie 11'], node: '8.9.4', }, modules: false, }), require('babel-preset-react'), ], plugins: [ require(' ...
Read more >
babel-loader
npm install -D babel-loader @babel/core @babel/preset-env webpack ... the loader will use the default cache directory in node_modules/.cache/babel-loader or ...
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