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.

Strip console logs from production builds

See original GitHub issue

Proposal: Automatically remove console.log statements from production builds while still keeping them in development builds.

Reasoning: Log statements can be useful to keep in development builds. However, they can be unnecessary and potentially sensitive to include in production builds. Currently, CRA does nothing with console logs, so if you want to have log messages in development, they must be manually removed for a production build.

Potential Solutions: There is a webpack loader that can strip aritrary code including console logs https://github.com/yahoo/strip-loader. We could also update our use UglifyJsPlugin and provide the drop_console option to the compressor.

Downsides: Anytime code is removed from builds weird situations can arise. Particularly bad would be unintentional side effects inside of a console log statement, which would be removed only in production and may lead to hard to debug problems. Additionally, there may be times where you deliberately want to include specific log messages in production. We would then have to support a way to flag certain console log lines to not be stripped.

I wanted to open the discussion because I couldn’t find any prior issues about this feature.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
omninonsensecommented, Aug 8, 2017

Sorry to comment on a closed issue, but what about only stripping console.debug? I agree that log, warn and error should remain, though.

2reactions
alexgvozdencommented, Jul 3, 2018

@tbillington you are absolutely right, this is my mistake best address for this is react-native-cli 😃 sorry for an opinionated discussion

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - How can remove console.log in the production build ...
I am using this approach to avoid ejecting react-scripts if (process.env.NODE_ENV === 'production') { console.log = () => {} console.error ...
Read more >
The Simple Way to Remove JS Console Logs in Production
NODE_ENV line can be added into any file in your project, but it's a really easy way to automate console log removal for...
Read more >
How to Remove Console Statements From Production Build in ...
This simplest practice removes console statements from the production build, leaving you with a great debugging tool during development.
Read more >
Angular - How to remove console.logs in production build
Angular tutorial. This is example how remove console. logs in production build0:00 Use case0:40 Solution1:34 Trying to learn pianoAngular ...
Read more >
How to strip console.log() from production build - Laracasts
When I build a production release with gulp --production my javascript files are minified but all my console.log() calls are not stripped out....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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