最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - npx babel not reading configuration from babel.config.js - Stack Overflow

programmeradmin2浏览0评论

When running npx babel index.js from the mand 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 mand?

Cheers

When running npx babel index.js from the mand 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 mand?

Cheers

Share Improve this question edited Mar 13, 2020 at 0:22 Max Collier asked Feb 28, 2020 at 2:20 Max CollierMax Collier 6919 silver badges27 bronze badges 2
  • 1 Babel version ? – Mechanic Commented Mar 13, 2020 at 0:26
  • 1 npx babel --version gave 6.26.0 (babel-core 6.26.3) – Max Collier Commented Mar 13, 2020 at 0:31
Add a ment  | 

1 Answer 1

Reset to default 3 +50

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.

发布评论

评论列表(0)

  1. 暂无评论