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

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay