4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Next.jsのデバッグ設定で出るエラーの原因と対応方法('NODE_OPTIONS' は、内部コマンドまたは外部コマンド、 操作可能なプログラムまたはバッチ ファイルとして認識されていません)

Last updated at Posted at 2023-02-19

(※検索するとcross-env入れろとか、ちょっと荒っぽい対策だったので原因を書きました)

前書き

  • Next.jsのデバッグ方法を調べると、package.jsonscriptsを下記のように書き換えて実行すると書いてあります。
 "scripts": {
    "dev": "NODE_OPTIONS='--inspect' next dev",

ところが、Windows(VSCode)で実行すると、下記のようなエラーが出て?となります。
image.png

原因

npmがscriptsを実行する際、「コマンドプロンプト(cmd.exe)」を利用するように設定されているからです。
コマンドプロンプトでは、NODE_OPTIONS='--inspect' next devという記述は、構文エラーになります。

  • Windowsの場合、例えgit-bashを利用していても、npmの初期設定「cmd.exe」が使われる

npmがscripts実行で利用するシェルの確認方法

>npm config get script-shell
C:\WINDOWS\system32\cmd.exe

対策①(コマンドプロンプトが理解できる記述に変更する)

一番簡単な対応方法は、cmd.exeが理解する構文に変更するのが早いです。
(setで環境変数の設定をして、&& でコマンドを続けて実行)

set NODE_OPTIONS=--inspect && next dev

対策②(シェルをgit-bashに変更する)

npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"

(シェルをbashにすると、何か別の問題が発生した(詳細は失念)ので、①をお勧めします)

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?