avatarEdoardo Nosotti

Summary

The article provides a solution for when the Node.JS debugger in Visual Studio Code fails to attach after a restart or update.

Abstract

The article addresses a common issue faced by developers using Visual Studio Code (VSCode) where the integrated Node.JS debugger stops attaching to processes after a restart or system update. It explains how to initially activate the debugger using the "Debug: Toggle Auto Attach" feature through the Command Palette and suggests choosing the "Smart" configuration for ease of use. When the debugger fails to attach, the author recommends a two-step fix: first, disabling the Auto attach feature, and then re-enabling it, followed by restarting the application. The article emphasizes that simply restarting VSCode or the computer may not resolve the issue and provides a methodical approach to troubleshoot the problem.

Opinions

  • The author finds the inability of the Node.JS debugger to attach after a restart to be an unnecessary inconvenience, especially during busy days.
  • The author suggests that the "Smart" debugger configuration is suitable for most users, as it automatically attaches to relevant processes while ignoring scripts in /node_modules.
  • The author expresses that the solution provided, although reminiscent of the common "turn it off and on again" advice, includes a specific sequence of disabling and re-enabling the auto-attach feature, which is crucial for the fix to work.
  • The author is open to feedback and alternative solutions, indicating a willingness to learn more about why this issue occurs and how it can be better addressed.

Fix The Node.JS Debugger Not Attaching In Visual Studio Code

Photo by Donald Giannatti on Unsplash

Working without a debugger is a totally unnecessary evil these days. Visual Studio Code makes it very easy to enable the integrated Node.JS debugger and use the breakpoints in your code. Sometimes, after a restart of the computer or the Visual Studio Code application to install updates, the Node.JS debugger will not attach anymore. It’s so tedious, especially if it happens in a busy day. Of course, you can be smart and choose not to deploy updates in such a day, but you have little power over your computer just going FUBAR and crashing when you least wanted it.

A few times my VSCode debugger did not attach to the Node.JS processes after a restart of VSCode. I tried intentionally restarting the whole computer as well and did not work. There is a solution for that.

Prologue: Activating the Debugger

If you never activated the Debugger in the first place, this is how to do it.

Press Shift-Cmd-P (⇧⌘P) on a Mac or Ctrl-Shift-P on Windows and Linux to bring up the Command Palette. Type “debug”. Select “Debug: Toggle Auto Attach” and press Enter:

The Visual Studio Command Palette

A submenu will be displayed:

The submenu for the “Debug: Toggle Auto Attach” command in Visual Studio Code.

Multiple configurations are offered for the Debugger. “Smart” is a very common and convenient choice. It will automatically attach the Debugger to the processes you start from the integrated Terminal, but leave out any debugging configuration potentially found in the scripts in /node_modules (which are out of the scope of the current application being developed). If you are not experienced with debugging, just go with “Smart” for now.

What To Do When The Debugger Does Not Attach

If the Debugger is not attaching, the only working solution I found is to:

  1. Expicitly disable the Auto attach Bring up the Command Palette as described in the Prologue. Type “debug”. Select “Debug: Toggle Auto Attach” and press Enter. Select “Disabled” and press Enter.
  2. Re-enable the Auto attach Bring up the Command Palette as described in the Prologue. Type “debug”. Select “Debug: Toggle Auto Attach” and press Enter. Select the same setting you used before (such as: “Smart”) and press Enter.

Please note that skipping #1 will not work.

Finally, start your application again from the integrated Terminal and the Debugger should attach again.

It feels a bit like the old trusty “turn it off and on” advice that everybody gets every once in a while, but with a twist. Surprisingly, just rebooting VSCode or the computer does not work, at least on Mac.

Please let me know if it worked for you, or you have found a better solution or even found out why this happens in the first place!

Visual Studio Code
Nodejs
Programming
JavaScript
Software Development
Recommended from ReadMedium