How to remove console.log for Production in NextJS
![Jasser Mark Arioste Jasser Mark Arioste](https://api.reacthustle.com/image?url=https://static.reacthustle.com/uploads/f4f5cbec4f331597effb22a00.jpeg?w=40&q=100)
Jasser Mark Arioste
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