How can remove console.log in the production build of a React application created using create-react-app CRA?
if you don't have environment variable then you can jsut simply do. console. log = function () {}; I am using this on my live app to hides the console.
The Yellow warning box in React Native can be both helpful and annoying. There are many errors that can be ignored but end up blocking necessary pieces of the application. To disable the yellow box place console. disableYellowBox = true; anywhere in your application.
If you've previously installed create-react-app globally via npm install -g create-react-app , we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.
I am using this approach to avoid ejecting react-scripts
if (process.env.NODE_ENV === 'production') {
console.log = () => {}
console.error = () => {}
console.debug = () => {}
}
index.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import './styles/main.scss'
// replace console.* for disable log on production
if (process.env.NODE_ENV === 'production') {
console.log = () => {}
console.error = () => {}
console.debug = () => {}
}
ReactDOM.render(<App />, document.getElementById('root'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With