By: Achour Meguenni -

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

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:

  • The removeConsole option ensures that all console.log statements are removed when building for production.
  • This method is simple and requires no additional plugins or dependencies.

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 Meguenni

Passionate tech enthusiast and a self-taught web developer.

2025 Achour, All rights reserved.

  • Contact
  • Achourphp@gmail.com

Achour Meguenni

Passionate tech enthusiast and a self-taught web developer.

2025 Achour, All rights reserved.

  • Contact
  • Achourphp@gmail.com