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.

.babelrc or config package.json is not considered

See original GitHub issue

I’m submitting a bug report

Webpack Version: 4.9.1

Babel Core Version: 7.0.0-beta.49

Babel Loader Version: 8.0.0-beta.3

Please tell us about your environment: Windows 10

Current behavior: babel-loader doesn’t include config options from “.babelrc” or "package.json

Expected/desired behavior: babel-loader uses “.babelrc” or “package.jso”

webpack:

{
        test: /\.js$/,
        loader: 'babel-loader',
        options: {
          babelrc: true,
          cacheDirectory: true
        }
 }

workaround:

{
        test: /\.js$/,
        loader: 'babel-loader',
        options: {
          babelrc: true,
          extends: path.join(__dirname + '/.babelrc'),
          cacheDirectory: true
        }
 }
  • What is the expected behavior?

Before I configured babel trough “package.json”. I just regonized this issue because I disabled comments in babel and found comments in my output.

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:17
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
felixfbeckercommented, Aug 24, 2018

I’m affected by this too after trying to upgrade everything to v7. I think that this is only happening when transpiling node_modules (which I need to do for a dependency) - I don’t get any errors for the files in my project, but the config is not considered for files in node_modules and I get errors that plugins are missing.

Could it be that because these files are in node_modules, the config search “stops” at the package.json of the dependency, instead of traversing up? Or maybe looking in parent directories is broken in general?

3reactions
EvHauscommented, Aug 24, 2018

I have a similar problem. babel-loader works correctly if the .babelrc is right next to my package.json directory, but if it’s located 1 directory above (I use a monorepo) – then it’s not loaded.

Not sure if that’s intentional or not.

babel-loader@8.0.0-beta.4
@babel/core@7.0.0-beta.51

UPDATE: Our solution was to migrate from .babelrc to babel.config.js which is the new recommended configuration structure for monorepos.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Babel
Create a file called babel.config.json with the following content at the root of your project (where the package.json is). { "presets": [...], "plugins":...
Read more >
babelrc configuration placed in package.JSON - Stack Overflow
Babel will look for a .babelrc in the current directory of the file being transpiled. If one does not exist, it will travel...
Read more >
How to Setup Babel in Node.js - freeCodeCamp
Now add the folder to the workspace, and open your terminal. Let's initialize and create a package.json file for our app: npm init....
Read more >
Babel 7: Configuration, Preset, and Plugin Usage
For those who have never used Node.js, understand package.json as a various metadata holder for all modules used by the application, including ...
Read more >
配置文件 - Babel 中文文档
项目范围的配置. babel.config.json 文件,以及不同扩展名的文件. 相关文件的配置 .babelrc.json 文件,以及不同扩展名的文件; 带有 "babel" 键的 package.json 文件 ...
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