Get "PHP 8 in a Nuthshell" (Now with 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.

👋 Hi there! I'm Amit. I write articles about all things web development. If you enjoy my work (the articles, the open-source projects, my general demeanour... anything really), consider leaving a tip & supporting the site. Your support is incredibly appreciated!

Comments?