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

Viewed 3901

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?

2 Answers

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.

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.

Related