'NODE_OPTIONS' is not recognized as an internal or external command - still an issue
Asked Answered
R

4

12

I am following the guide from here on a nextjs application. Using VSCode on windows.

It says use the script: "dev": "NODE_OPTIONS='--inspect' next dev"

this results in:

'NODE_OPTIONS' is not recognized as an internal or external command, operable program or batch file.

Yes I know there is already a question with the same name but it is 2.5 years old, has 8k views and no accepted answer. I am unable to comment to add information to it. Feel free to mark this as a duplicate but please at least link it in a comment in the other question.

The one answer that is there advises installing yet another (maintenance mode) dependency and configuring it to change environment variables.

This and other research leads me to believe that there is an issue with environment variables here. Can't I just set them manually? Why is this not mentioned in the official next guide? How can I set the correct environment variable?

Rom answered 15/6, 2021 at 21:18 Comment(3)
Possibly related: github.com/vercel/next.js/issues/22835Rom
Does this answer your question? "NODE_ENV" is not recognized as an internal or external command, operable command or batch fileSchoolfellow
Some of the answers are relevant, in that they shed light on the issue. But none of the answers there helped solve the issue. Using "SET NODE_OPTIONS='--inspect' & next dev" as suggested in one of them resolves the error message, but the application does not start with the debugger listening so it appears to just be hiding the error not fixing it.Rom
T
15

There is a way to get it working and you can find a similar question posted here.

Step 1

npm i cross-env --save-dev

Step 2

Edit your package.json so the dev option looks like this

    {
      "scripts": {
        "dev": "cross-env NODE_OPTIONS='--inspect' next dev",
        "build": "next build",
        "start": "next start"
      }
    }

Step 3

You can now launch your NextJS program in a separate terminal. After that follow the NextJS VSCode debugging instructions. Attach VSCode to the running NextJS instance.

You're all set.

Twoedged answered 31/8, 2021 at 13:57 Comment(0)
C
2

Maybe this can help us

Debugging on Windows

Windows users may run into an issue when using NODE_OPTIONS='--inspect' as that syntax is not supported on Windows platforms. To get around this, install the cross-env package as a development dependency (--dev with NPM or -D for Yarn) and replace the dev script with the following.

"dev": "cross-env NODE_OPTIONS='--inspect' next dev",

cross-env will set the NODE_OPTIONS environment variable regardless of which platform you are on (including Mac, Linux, and Windows) and allow you to debug consistently across devices and operating systems.

Crosspollination answered 16/7, 2022 at 21:14 Comment(1)
And if "cross-env" not recognized as an internal command, install: cross-env with 'yard add cross-env' en run the serverCrosspollination
D
0

Without cross-env, natively on Windows

The correct syntax for any current version of Windows (these all use Powershell) is:

$env:NODE_OPTIONS="INSPECT"

To make Linux instructions just work

Install WSL, so you can use bash, Linux node, Linux binaries in npm, etc.

Duprey answered 16/3, 2023 at 22:2 Comment(0)
S
0

in your .env.local file (i assume that you using next dev) just add the variable and run the "npm run dev".(no need to change package.json . just leave it as default settings).

your .env.local file

other variables ...
NODE_OPTIONS="--inspect"
Suggest answered 28/7 at 8:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.