How to remove console statements from React Native apps

September 29, 2022

How to remove console statements from React Native apps

How to remove console statements from React Native apps

How to use it

I have"@babel/core": "^7.5.5"and"react-native": "^0.63"
The approach described in React Native Documentationwas not working for me.

After many try and error and exploring issues on GitHub I got it working :

In babel.config.js add this -

module.exports = api => {
  const babelEnv = api.env();
  const plugins = [];
  //change to 'production' to check if this is working in 'development' mode
  if (babelEnv !== 'development') {
    plugins.push(['transform-remove-console', {exclude: ['error', 'warn']}]);
  }
  return {
    presets: ['module:metro-react-native-babel-preset'],
    plugins,
  };
};

To see changes run using npm start -- --reset-cache


Written by Manoj Bhardwaj who lives and works in Dharamshala Himachal Pradesh (India). My stackoverflow