Stop Forgetting! Automatically Remove console.log in Next.js Production

We always tend to forget to remove console.log statements before pushing our code to production. While these logs are useful for debugging, they can clutter the console, expose unnecessary details, and even affect performance

We always tend to forget to remove console.log statements before pushing our code to production. While these logs are useful for debugging, they can clutter the console, expose unnecessary details, and even affect performance

How to Remove console.log in Production in Next.js

We always tend to forget to remove console.log statements before pushing our code to production. While these logs are useful for debugging, they can clutter the console, expose unnecessary details, and even affect performance. Instead of manually removing them every time, why not be smart and automate the process? Next.js provides a simple built-in way to strip out console.log statements in production.

Steps:

  1. Open or create a next.config.js file in your project’s root directory.
  2. Add the following configuration:
module.exports = {
  compiler: {
    removeConsole: process.env.NODE_ENV === "production",
  },
};

Explanation:

Conclusion

By using the removeConsole option in next.config.js, you can easily prevent console.log statements from appearing in production builds, keeping your application clean and efficient.

© Achour.dev 2025, All rights reserved.