Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug babel.config.js

I've noticed that there are virtually no info from babel on incorrect configuration. For example I've created new app with react-native-cli, installed decorators plugin and filled my babel.config.js as follows:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: ['@babel/plugin-proposal-decorators', { legacy: true }],
};

And there were the same complain as if no plugin is installed. Correct config would be:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
};

Now I'm trying to install jsx-control-statements and have the same silent fail causing ReferenceError: Can't find variable: Choose as if no such plugin is installed at all. My babel.config.js is:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    'jsx-control-statements',
    ['@babel/plugin-proposal-decorators', { legacy: true }],
  ],
};

So the question is: How do I debug this configuration? How can I get some diagnostic from babel about incorrect configuration/not found packages etc.?

like image 521
Ilya Denisov Avatar asked Oct 03 '19 22:10

Ilya Denisov


People also ask

Where is my Babel config file?

babelrc file is your local configuration for your code in your project. Generally you would put it in the root of your application repo. It will affect all files that Babel processes that are in the same directory or in sibling directories of the . babelrc .

Where is Babel config js react?

Where can I find the babel configuration of a non ejected application made with create-react-app ? It's in the Webpack config of the react-scripts/config directory.

What is Babel config js in react native?

React Native itself uses this Babel preset by default when transforming your app's source code. If you wish to use a custom Babel configuration by writing a babel. config. js file in your project's root directory, you must specify all the plugins necessary to transform your code.


1 Answers

For instance if the presets/plugins are missing or missconfigured, you'll get an error when webpack takes over and try to load all the config. But I think your best shot is to use progressPlugin where you could display each step and see for yourself what is happening.

new webpack.ProgressPlugin((percentage, message, ...args) => {
    console.log(percentage, message, ...args);
  }),

Another approach, would be using debug module, as nearly all other plugins, modules use it.

DEBUG=* webpack [-c webpack.something.js]

Hope it helps

like image 160
ROUINEB Avatar answered Oct 17 '22 05:10

ROUINEB