{
"$type": "site.standard.document",
"canonicalUrl": "https://blog.nove-b.dev//posts/remove-console-next-production",
"path": "/posts/remove-console-next-production",
"publishedAt": "2025-04-26T00:00:00.000Z",
"site": "at://did:plc:2atly2y5kfyjcj5zap6pv4wd/site.standard.publication/3mmxeqr2tcb2k",
"tags": [
"nextjs"
],
"textContent": "結論\n\n上記コードでnextjsのproduction\nビルド時にconsoleが出力されなくなる。にした。\n\nデバッグしないと進めない\n\nコードを見て何が起きいるのかわかるくらいの玄人であれば問題ないんだけど、そんな技術力はなく、consoleを出しまくり、どこで何がどうなっているのかを確認しないと進めない。\n\nそんな具合なのでコンソール画面には大量のログが溢れる。\n\n当然そんな状況じゃ、デプロイできないので、いちいちconsoleを消すのは面倒だし、そのまま開発環境ではconsoleを使いたい。\n\nなので、デプロイ時だけ消したい。\n\n本番環境でだけconsoleを消したい\n\nnextjsでは設定でデプロイ時だけconsoleを出力しない方法があるので実行した。\n\nてかたぶん、ほとんどのフレームワークにはあると思うんだけど。\n\nnext.config.jsで下記設定をする。\n\nNODE_ENVを自身で定義する必要があると思ったけど、\n\n公式を参照すると、\n\n> The greater React ecosystem treats NODE_ENV as a convention, only permitting\n> three (3) values:\n\n> production: When your application``` is built with next build development:\n> When your application is run with next dev test: When your application is\n> being tested (e.g. jest)\n\nのように事前に定義されているっぽい。\n\nこれでどんどんconsole`を出力できる。",
"title": "nextjs のproduction環境でだけconsoleを出力しないようにする"
}