ReactHustle

How to remove console.log for Production in NextJS

Jasser Mark Arioste

Jasser Mark Arioste

How to remove console.log for Production in NextJS

Sometimes we need to remove console.log for Production in NextJS. I've seen many tutorials that modify the console.log function but I think this tutorial is the cleanest and most elegant way to remove console.log messages.

We'll just have to modify next.config.js:


/** @type {import('next').NextConfig} */
const nextConfig = {
  ...
  compiler: {
    removeConsole: process.env.NODE_ENV === "production"
  },
}
12345678

NextJS v12 config has a compiler option removeConsole that accepts a boolean value, so we just have to check if the NODE_ENV is equal to "production".

That's it!

If you like tutorials like these please leave a like or subscribe to our newsletter down below!

Credits: Image by Julius Silver from Pixabay

Share this post!

Related Posts

Disclaimer

This content may contain links to products, software and services. Please assume all such links are affiliate links which may result in my earning commissions and fees.
As an Amazon Associate, I earn from qualifying purchases. This means that whenever you buy a product on Amazon from a link on our site, we receive a small percentage of its price at no extra cost to you. This helps us continue to provide valuable content and reviews to you. Thank you for your support!
Donate to ReactHustle