question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`transform-remove-console` exclude options not working on React Native project

See original GitHub issue

Describe the bug

I’m using the exclude options but it doesn’t seem to have any effect as all logs are removed.

To Reproduce

.babelrc

{
  "presets": ["react-native", "react-native-dotenv"],
  "env": {
    "production": {
        "plugins": [ ["transform-remove-console", { "exclude": [ "error", "warn", "info"] }] ]
    }
  }
}

Actual Output

All console.* output is removed.

Expected Output

console.warn, console.info and console.error should still work.

Configuration

How are you using babel-minify?

“metro-minify-uglify”

Additional context

React Native 0.54.4

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

32reactions
bareynolcommented, Oct 8, 2019

For anyone that happens upon this, and has been affected by it, I’ve found that using the following as my babel.config.js works properly to include transform-remove-console in production builds for react native projects, and properly uses the exclude property if specified:

module.exports = function(api) {
  api.cache(true);
  if (process.env.NODE_ENV === 'production' || process.env.BABEL_ENV === 'production') {
    return {
      "presets": ["module:metro-react-native-babel-preset"],
      "plugins": ["react-native-paper/babel", ["transform-remove-console", {"exclude": ["error", "warn", "info"]}]]
    }
  } else {
    return {
      "presets": ["module:metro-react-native-babel-preset"],
    }
  }
}
1reaction
bareynolcommented, Oct 7, 2019

I updated to react-native 0.61.2 and modified my babel.config.js to return a function with the signature function(api)

module.exports = function(api) {
  console.log("BABELCONFIG", api.version, api.env("production"), api.env(), process.env.NODE_ENV, process.env.BABEL_ENV);
  return {
    "presets": ["module:metro-react-native-babel-preset"],
    "plugins": ["react-native-paper/babel", "transform-remove-console"]
  }
}

During build I get the following output:

transform[stdout]: BABELCONFIG 7.6.2 true production production production
transform[stdout]: BABELCONFIG 7.6.2 true production production production
transform[stdout]: BABELCONFIG 7.6.2 true production production production
transform[stdout]: BABELCONFIG 7.6.2 true production production production
transform[stdout]: BABELCONFIG 7.6.2 false undefined production undefined
transform[stdout]: BABELCONFIG 7.6.2 false undefined production undefined
transform[stdout]: BABELCONFIG 7.6.2 false undefined production undefined
transform[stdout]: BABELCONFIG 7.6.2 true production production production
transform[stdout]: BABELCONFIG 7.6.2 true production production production
transform[stdout]: BABELCONFIG 7.6.2 false undefined production undefined
transform[stdout]: BABELCONFIG 7.6.2 false undefined production undefined
transform[stdout]: BABELCONFIG 7.6.2 false undefined production undefined

using plugins at top level allows the listed plugins to work, but using the env: {production: { plugins: [...]}} format does not work.

It appears as though BABEL_ENV is sometimes set to ‘production’ and sometimes undefined, and NODE_ENV is not being used when BABEL_ENV is undefined. I’m at a loss as to why

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native 0.60.3 babel-plugin-transform-remove-console ...
I have "@babel/core": "^7.5.5" and "react-native": "^0.60.5" The approach descibed in React Native Documentation was not working for me.
Read more >
babel-plugin-transform-remove-console
Options. exclude - An array of console methods to exclude from removal. You can read more about configuring plugin options here.
Read more >
React Native 0.60.3 babel-plugin-transform-remove-console ...
The approach descibed in React Native Documentation was not working for me. After many try and error and exploring issues on GitHub I...
Read more >
Button - React Native
Supports a minimal level of customization. If this button doesn't look right for your app, you can build your own button using TouchableOpacity ......
Read more >
React Native Final Steps - Red Shift
Check Startup Speed for Performance Issues; Bulletproof Your App; Re-enable ATS. 1. Remove Console.logs. As you might or might not know, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found