metro icon indicating copy to clipboard operation
metro copied to clipboard

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

Open Victorien-Tardif opened this issue 4 years ago • 6 comments

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,
      },
    ],
  ],
};

Victorien-Tardif avatar Oct 29 '19 10:10 Victorien-Tardif

Reading this https://github.com/facebook/metro/blob/faef2e6c6dfcfdd3e3fa4e25ac823ef99440a185/packages/metro-react-native-babel-transformer/src/index.js#L80 I now understand the problem but what should be done?

Victorien-Tardif avatar Oct 29 '19 12:10 Victorien-Tardif

Reading this

https://github.com/facebook/metro/blob/faef2e6c6dfcfdd3e3fa4e25ac823ef99440a185/packages/metro-react-native-babel-transformer/src/index.js#L80

I now understand the problem but what should be done?

Hi~Have you solved the problem? I config the 'babelTransformerPath' in metro.config.js, but I hope the 'metro-react-native-babel-transformer' can support to set on the root, or is there another way?

sudoooooo avatar May 24 '20 06:05 sudoooooo

Reading this https://github.com/facebook/metro/blob/faef2e6c6dfcfdd3e3fa4e25ac823ef99440a185/packages/metro-react-native-babel-transformer/src/index.js#L80

I now understand the problem but what should be done?

Hi~Have you solved the problem? I config the 'babelTransformerPath' in metro.config.js, but I hope the 'metro-react-native-babel-transformer' can support to set on the root, or is there another way?

Hi, I did not solved the problem no :/ I just found a way to transpile everything with one config. That's not ideal at all.

Victorien-Tardif avatar May 25 '20 07:05 Victorien-Tardif

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.

draperunner avatar Aug 12 '20 09:08 draperunner

Any updates on this?

danilhendrasr avatar Oct 26 '21 00:10 danilhendrasr

I spent a lot of time trying to troubleshoot this and then came across this issue. I'll try patching metro-react-native-babel-transformer but it would be nice to get some official support!

eliw00d avatar Jun 06 '22 16:06 eliw00d

Any updates?

mikebrsv avatar Nov 23 '22 13:11 mikebrsv