Reputation: 533
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?
Upvotes: 13
Views: 19128
Reputation: 21
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"
Upvotes: 2
Reputation: 123198
The correct syntax for any current version of Windows (these all use Powershell) is:
$env:NODE_OPTIONS="INSPECT"
Install WSL, so you can use bash, Linux node, Linux binaries in npm, etc.
Upvotes: 0
Reputation: 21
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.
Upvotes: 2
Reputation: 799
There is a way to get it working and you can find a similar question posted here.
npm i cross-env --save-dev
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"
}
}
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.
Upvotes: 15