Get "PHP 8 in a Nuthshell" (Soon includes PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Disable console logs in production in Next.js

Believe it or not, console logging things is still the most used debugging technique by developers. No matter how many advanced tools are available for debugging, logging in to the console still has a sweet spot among developers.

And though, it’s pretty convenient to just dump things in the browser console, it can look sloppy if it ends up in your production.

Next.js has a pretty handy configuration that you can use to get around this issue. Thanks to this handy tip by Alex Sidorenko.

To disable the console logs in production, you need to set the compiler.removeConsole option to true in the next.config.js file like so.

// next.config.js

const nextConfig = {
  compiler: {
    removeConsole: process.env.NODE_ENV === 'production',
  },
};

export default nextConfig;

And that’s it. Now, you don’t need to worry about messy console logs in production even if they somehow slip through.

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?