DEV Community

Paweł Fraś
Paweł Fraś

Posted on

3

How overwriting NODE_OPTIONS can ruin your debugger in Visual Studio Code 😬

When using Visual Studio Code daily, you may use JavaScript Debug Terminal to debug your Node.js apps. If you do so, one day, you may struggle with the same issue I did some time ago.

Problem

When I tried to run a Node.js application in the Javascript Debug Terminal, I noticed the debugger was not attaching to the process as it used to, regardless of whether breakpoints were set.

The problem was related to the NODE_OPTIONS I set in my terminal config file—not the fact that I added it, but the way I did it. It turned out that the debugger in VSC uses the special NODE_OPTIONS environment variable, and overwriting it may lead to unexpected behaviors.

Solution

Instead of overwriting the variable, you should extend it with your options. For example, the config file (.zshrc in my case) might contain something like this:

- export NODE_OPTIONS="--some-other-option=here"
+ export NODE_OPTIONS="$NODE_OPTIONS --some-other-option=here"
Enter fullscreen mode Exit fullscreen mode

sidenote: This also applies to Cursor!

source: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_how-can-i-set-nodeoptions

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series