Remove All type of console log in Production , App directory
Unanswered
Cape lion posted this in #help-forum
Cape lionOP
I'm trying to remove all console.log statements from my Next.js production build, but the approach below doesn't seem to work:
I'm currently using Next.js version 14.2.5, and I still see runtime logs appearing in production (as shown in the attached images).
Does anyone know how to properly strip console logs from the production build? Any help would be appreciated.
compiler: {
// Attempting to remove console logs in production
removeConsole: process.env.NODE_ENV === 'production',
},
I'm currently using Next.js version 14.2.5, and I still see runtime logs appearing in production (as shown in the attached images).
Does anyone know how to properly strip console logs from the production build? Any help would be appreciated.
13 Replies
the last 3 are because of browser
you cannot remove them
the top 4 are react
its telling you the error about your code
can't remove that either
the above config only works for logs you add in your code
Cape lionOP
any word around??
here is how when i fetch something i display the logs do i have remove one by one???
here is how when i fetch something i display the logs do i have remove one by one???
there are no work around, the api request error log you see is because of your browser
its your browser showing them, not code
you could, however, try calling console.clear() if request fails and see if it does something
it should ideally clear the console
Cape lionOP
What do you think about creating a component that clears the console every 2 seconds? Would that hurt performance?
Yes, this is bad, the logs are here for you. If you hide them, and you have a problem in production from a user, you won’t be able to debug and fix