npx babel not reading configuration from babel.config.js
Asked Answered
E

1

6

When running npx babel index.js from the command line, I was hoping I would see my babel configurations being applied from babel.config.js

However it does not seem the case as was wondering why this might be?

// babel.config.js
module.exports = function babel(api) {
 api.cache(true);
   return {
     presets: ['module:metro-react-native-babel-preset'],
     plugins: [
       [
         'babel-plugin-root-import',
         {
           rootPathSuffix: './src',
           rootPathPrefix: '~/',
         },
       ],
     ],
   };
 };

// index.js
import { AppRegistry } from 'react-native';
import App from '~/App';
AppRegistry.registerComponent("App Name", () => App)

// Expected output from npx babel index.js
import { AppRegistry } from 'react-native';
import App from './src/App'; // Note the change from '~' to './src' using babel-plugin-root-import
AppRegistry.registerComponent("App Name", () => App)

I noticed in the npx babel --help it stated that --no-babelrc flag ignores configuration from .babelrc and .babelignore files. Does this suggest that babel.config.js files aren't considered when calling this command?

Cheers

Elmoelmore answered 28/2, 2020 at 2:20 Comment(2)
Babel version ?Marita
npx babel --version gave 6.26.0 (babel-core 6.26.3)Elmoelmore
M
3

babel.config.js config change is introduced in babel 7; so if you are using babel 6.*, it doesn't understand project wide configuration yet; either use .babelrc or upgrade to babel 7 to be able to use new features; I'd did the upgrade its pretty smooth and painless, just make sure you have clean git directory ( in case of emergency :) and do it.

Marita answered 13/3, 2020 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.