Try this configuration in your launch file:

{
    "name": "Attach to Process",
    "type": "node",
    "protocol": "inspector",
    "request": "attach",
    "stopOnEntry": false,
    "port": 5858,
    "localRoot": "${workspaceRoot}",
    "remoteRoot": "/somepath/myprojectroot",
    "sourceMaps": true
}

Make sure the remoteRoot is correct path, otherwise it won't know where to look for the source files.

Answer from alkasai on Stack Overflow
🌐
GitHub
github.com › microsoft › vscode › issues › 107251
VSCODE does not stop on breakpoints in Node.js apps · Issue #107251 · microsoft/vscode
September 22, 2020 - I recently updated(big mistake apparently!) and now no version of node on my system will stop on breakpoints. Does this issue occur when all extensions are disabled?: Yes/No YES Does this issue occur with various node versions: YES it does · I've also noticed that vscode does not pass along a "debug" arg to node.
Author   jxmot
Discussions

Debugger not stopping on breakpoints
Hey! I'm having issues similar to microsoft/vscode#103048, wanted to create a new issue so I'm not hijacking threads, it seemed like some people over there were having issues with NPM scrip... More on github.com
🌐 github.com
8
July 26, 2020
Vscode node debugger not stopping on breakpoints when launching with nodemon
VSCode Version: 1.10.2 OS Version: Windows 7 Profesionnal, SP1 Hi everyone. I'm trying to debug typescript code (or javascript code) in server side with visual studio code, when launching it wi... More on github.com
🌐 github.com
19
April 4, 2017
Node.js v23.2.0: Breakpoints not binding in VS Code debugger
Version v23.2.0 Platform Microsoft Windows NT 10.0.19045.0 x64 Subsystem Node.js Debugger (V8 Inspector) What steps will reproduce the bug? Install Node.js v23.2.0 Create a simple JavaScript file: ... More on github.com
🌐 github.com
10
November 21, 2024
typescript - VSCode not stopping at breakpoints when test launched using npm and package.json scripts - Stack Overflow
From within VSCode I would like to launch the current file (e.g. my-function.spec.ts) and do interactive debugging setting breakpoints. For the test to run I need to set some environment variables... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › nodejs › node › issues › 56156
Breakpoint Debugging Not Working with Node.js 23.2.0 and 23.3.0 in Visual Studio Code · Issue #56156 · nodejs/node
December 6, 2024 - Run the application using the debugger. Observed Behavior Breakpoints fail to set correctly, and Visual Studio Code shows a message indicating that some breakpoints cannot be applied. The application continues execution without stopping at the breakpoints.
Author   IsmaelCoulibalyPLRM
🌐
GitHub
github.com › microsoft › vscode-js-debug › issues › 660
Debugger not stopping on breakpoints · Issue #660 · microsoft/vscode-js-debug
July 26, 2020 - I'm having issues similar to microsoft/vscode#103048, wanted to create a new issue so I'm not hijacking threads, it seemed like some people over there were having issues with NPM script arguments which is definitely unrelated for me. Describe the bug When the preview is enabled (now default), no breakpoints, debuggers, or initial breaks are hit. The program runs and exits with code 0 (if the node event loop is clear). To Reproduce Ubuntu 18.04, Using NVM globally, Node binary at 14.3.0, VSCode at 1.47.2, all built-in plugins enabled.
Author   jonathanrdelgado
🌐
Visual Studio Code
code.visualstudio.com › docs › nodejs › nodejs-debugging
Node.js debugging in VS Code
November 3, 2021 - However, if the debugger hits a ... the debug session will not end. In this case, pressing Stop again will force terminate the debuggee and its child processes (SIGKILL)....
🌐
GitHub
github.com › Microsoft › vscode › issues › 23900
Vscode node debugger not stopping on breakpoints when launching with nodemon · Issue #23900 · microsoft/vscode
April 4, 2017 - And the nodejs server is restarting as expected when a javascript file is generated. But I am not able to break on any breakpoint (on typescript files or javascript files). Can you tell me please if it is an issue or if there is something I am missing ? ... debugDebug viewlet, configurations, breakpoints, adapter issuesDebug viewlet, configurations, breakpoints, adapter issues ... You can’t perform that action at this time.
Author   TitaneBoy
🌐
GitHub
github.com › nodejs › node › issues › 55948
Node.js v23.2.0: Breakpoints not binding in VS Code debugger · Issue #55948 · nodejs/node
November 21, 2024 - Debugger should pause execution at set breakpoints, allowing inspection of program state. Program runs without stopping at breakpoints.
Author   carlmattsimpao
Find elsewhere
🌐
Reddit
reddit.com › r/vscode › vs code debug not stopping on breakpoints
r/vscode on Reddit: VS Code debug not stopping on breakpoints
June 10, 2023 -

I'm new to using VS Code as I¡ve always used Eclipse IDE. I'm trying to debug my java file in which I've created a breakpoint, but the debugger just runs the code as if there wasn't such breakpoint..

I've seen some other people struggle with this, so here's my launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Java",
            "type": "java",
            "request": "launch",
            "stopOnEntry": true,
            "jdkPath": "${env:JAVA_HOME}/bin",
            "cwd": "${fileDirname}",
            "startupClass": "${fileBasenameNoExtension}",
            "classpath": [
                ".",
                "${fileDirname}"
            ]
        },
        {
            "name": "Java Console App",
            "type": "java",
            "request": "launch",
            "stopOnEntry": true,
            "jdkPath": "${env:JAVA_HOME}/bin",
            "cwd": "${fileDirname}",
            "startupClass": "${fileBasenameNoExtension}",
            "classpath": [
                ".",
                "${fileDirname}"
            ],
            "externalConsole": true
        },
        {
            "type": "java",
            "name": "Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
        {
            "type": "java",
            "name": "Numeros",
            "request": "launch",
            "mainClass": "Numeros",
            "projectName": "progra_4bad0bd0"
        }
    ]
}

Thanks in advance

🌐
Medium
medium.com › rockedscience › fix-nodejs-debugger-vscode-401277e2e9be
Fix The Node.JS Debugger Not Attaching In Visual Studio Code | RockedScience
May 16, 2023 - 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.
Top answer
1 of 1
1

Disclaimer: This is not a solution, this is just me trying to answer the question the best I can because it tickled my curiosity and I found it very interesting. The following are facts, and the reasons why it is not working are just my assumptions.


What are breakpoints, and how do they work?

I'm sure you know about debuggers since you already use one, or at least, how they work globally, on the surface.

I won't go into details about software and hardware breakpoints, how do they work in details etc. since others already have and in a way better manner that I could ever achieve.

However, in short, breakpoints (debuggers, in fact, breakpoints are just a functionality of a debugger) rely on code injection in order to work.

The INT 3 instruction, as its name implies, interrupts the execution of the program where it has been injected.

We now know that breakpoints, in our case, will be injected in our code so that Node, our interpreter, will transform that to an INT 3 instruction that can be caught by our debugger.

Aliases on shells

Aliases are usually just strings to, well, alias, a long command line.

Normally, according to Bash manual (and I believe that's the case for other shells), all aliases are replaced before executing any of the compound command-line:

Bash always reads at least one complete line of input, and all lines that make up a compound command, before executing any of the commands on that line or the compound command. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read

I cannot guarantee that this is the case with zsh though, since they are not as extensive regarding how it works in the background.

So, under normal circumstances, nothing should impair the injection.

VSCode and its terminal

Now, you mentioned launching these under the VSCode terminal. I can't tell for sure because I use JetBrains IDEs, but you must be using this feature to automatically attach the debugger to any node-related project, right?

If that's the case, my assumption is that the VSCode terminal supersedes, or enhances, the shell it is using in the background, in the sense that it is acting before zsh parses your command-line.

VSCode terminal handler parses your command-line first, acknowledges that there is no node in your command-line and so, delegates the execution to the shell its using, zsh in this case. If you work with JavaScript, think of this instance of the VSCode terminal as a middleware.

The sentence that made me think this way is the following:

If the Auto Attach feature is enabled, the Node debugger automatically attaches to certain Node.js processes that have been launched from VS Code's Integrated Terminal

... implying only NodeJS processes would be affected.

But that's only my assumption and I could be completely wrong.

Now, is there a way to solve this, keeping the same features (auto-attach, aliases)? If it works like I think it does, I'm afraid not..

🌐
Stack Overflow
stackoverflow.com › questions › 65208753 › node-runs-code-but-does-not-stop-at-breakpoints-in-vscode
node.js - node runs code but does not stop at breakpoints in vscode - Stack Overflow
December 9, 2020 - On further inspection, it appears as though the debugger is working but the code starts first and the debugger attaches later about after 500 lines of code have run. One can replicate this by running the same code in a for loop to 1000 with a breakpoint on the console.log() line.
🌐
GitHub
github.com › microsoft › vscode › issues › 113283
NodeJs: Debugger not stopping at breakpoint (WSL2/Ubuntu18) · Issue #113283 · microsoft/vscode
December 22, 2020 - Using WSL2/Ubuntu18 I've not been able to make the VSCode NodeJs Debugger to stop on the breakpoints of any NodeJs app. When I start the debugger, it runs (I can see the output on the integrated terminal) but breakpoints are simply ignor...
🌐
Super User
superuser.com › questions › 1495144 › visual-studio-code-debugger-for-node-application-stops-at-runmicrotasks-in-next
Visual Studio Code debugger for Node application stops at runMicroTasks in next_tick.js instead of in the specified breakpoint
October 23, 2019 - The solution is simply to click on the top of the call stack in the debugger view on the side(refer screenshot). ... Additionally for subsequent breakpoints, if the debugger always stops at the next_tick.js file, then in the call stack in the ...
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360003315260-Node-JS-Debugger-not-hitting-breakpoints
Node JS Debugger not hitting breakpoints – IDEs Support (IntelliJ Platform) | JetBrains
Yes, this can indeed be the issue - NODE_OPTIONS environment variable is used by the debugger for automatic connection to child processes, so redefining NODE_OPTIONS breaks the debugger.
🌐
GitHub
github.com › microsoft › vscode › issues › 22761
Node debugger not stopping on breakpoints when connected remotely to Docker · Issue #22761 · microsoft/vscode
However, if I bring up the service in a container (using npm start stack:debug), manually adding a debugger; statement causes code to break execution; however, a breakpoint in VS Code does not. Webpack is outputting the compiled files with inline source maps into ./dist. I'm reasonably confident that I've got the localRoot and remoteRoot correct as, if I muck about with them at all, my breakpoints go grey.
🌐
Stack Overflow
stackoverflow.com › questions › 53197701 › vscode-debugger-not-stopping-on-breakpoints-while-debugging-a-remote-node-server
node.js - VScode debugger not stopping on breakpoints while debugging a remote node server - Stack Overflow
November 8, 2018 - I'm trying to debug my remote node server through VSCode and it doesn't stop on any of the breakpoints i've configured. I'm running VSCode on my mac where i have one copy of the node project and i have another copy of the same node project on a remote machine, both copies of the node project are synced. i'm running the node server on the remote machine using the following command: ... { "name": "Attach", "type": "node", "request": "attach", "port": 5858, "address": "remote server addr", "localRoot": "${workspaceFolder}", "remoteRoot": "the path to project directory on remote server", "protocol": "auto" }
🌐
GitHub
github.com › vitest-dev › vitest › issues › 5380
Debugger in vs-code does not stop at breakpoint but elsewhere · Issue #5380 · vitest-dev/vitest
March 13, 2024 - Describe the bug In vanilla project with vue3 + vitest + @testing-library/vue + node 18.18.2 or 20.11.1, setting and debugging breakpoints in vs-code on windows 11 does not work as expected. Debugger stops at wrong location. I am using v...
Author   bonham
🌐
GitHub
github.com › Microsoft › vscode › issues › 45448
Doesn't stop on breakpoints · Issue #45448 · microsoft/vscode
September 3, 2018 - Issue Type: Bug Set a breakpoint and run. It does not stop anymore. I believe 1.20 and earlier worked, but not in 1.21. This happens when running a test suite via jest is against code using TypeScript (v2.7.2) and using ts-jest (v21.2.4)...
Author   manu-st