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.

Why can't I use the babelrcRoots option in babel.config.js file?

See original GitHub issue

Do you want to request a feature or report a bug?

A bug I guess

What is the current behavior?

When specifying the babelrcRoots, bundling fails with a babelrcRoots is not allowed in .babelrc or "extend"ed files' error but… This is my main babel.config file and I don’t understand why it would be extended? I suspect metro to extend it but… then what can I do?

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

Just add the babelrcRoots option in the babel.config.js file

What is the expected behavior?

This option should just be available, I need some sub-modules to be transpiled with their own .babelrc files and they are not as I can’t specify the babelrcRoots.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

metro 0.56.3 RN 0.61.2 node 10.16.0 macOS Catalina 10.15

metro.config.js file

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
};

babel.config.js file

module.exports = {
  babelrcRoots: [
    /node_modules\/@NoduModulesWithTheirOwnBabelRcFiles/,
  ],
  presets: [
    'module:metro-react-native-babel-preset',
  ],
  plugins: [
    'transform-inline-environment-variables',
    [
      'react-intl-auto',
      {
        filebase: true,
        includeExportName: true,
      },
    ],
  ],
};

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

2reactions
draperunnercommented, Jun 6, 2022

We are using Yarn Workspaces and are patching metro-react-native-babel-transformer/src/index.js using patch files:

    babelRC = {
      plugins: [],
+     babelrcRoots: [ '../*' ],
      extends: extendsBabelConfigPath
    };

This works, but suddenly there is a version mismatch in the dependencies of react-native and @react-native-community/cli. One depends on metro-react-native-babel-transformer v0.59 and the other v0.58. This breaks our patch, as the CLI’s transformer is put somewhere else in node_modules.

It would be great to have a way to specify babelrcRoots without having to patch node_modules.

0reactions
mikebrsvcommented, Nov 23, 2022

Any updates?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Config Files - Babel.js
json is within a sub-package, not the root package. To enable processing of that .babelrc.json , you will want to use the "babelrcRoots"...
Read more >
javascript - Trying to configure Babel in a monorepo project
This is probably caused by react-native-modal not transpiling class property syntax. And, by default, node_modules will not be transpiled.
Read more >
升级至 Babel 7 (API)
Dropped use of add-module-exports plugin on Babel packages. ... Adds support for a babel.config.js file along the lines of what Webpack does.
Read more >
gatsby-transformer-react-docgen - npm
babelrc will be used to determine how to parse source files. Don't worry if you don't have a local babel config and are...
Read more >
TransformOptions | @open-rpc/typings
Specify whether or not to use .babelrc and .babelignore files. ... Defaults to searching for "babel.config.js" inside the "root" folder. false will disable ......
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