microsoft / vscode-js-debug

A DAP-compatible JavaScript debugger. Used in VS Code, VS, + more
MIT License
1.67k stars 283 forks source link

Node debugger fails to run when launching a process with NODE_OPTIONS=--no-node-snapshot #2115

Closed sonikro closed 3 weeks ago

sonikro commented 3 weeks ago

Does this issue occur when all extensions are disabled?: Yes

Version: 1.94.2 (system setup) Commit: 384ff7382de624fb94dbaf6da11977bba1ecd427 Date: 2024-10-09T16:08:44.566Z Electron: 30.5.1 ElectronBuildId: 10262041 Chromium: 124.0.6367.243 Node.js: 20.16.0 V8: 12.4.254.20-electron.0 OS: Windows_NT x64 10.0.19045

Steps to Reproduce:

  1. Create a simple project with the following package.json
{
  "name": "sandbox",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "start-no-snapshot": "NODE_OPTIONS=\"--no-node-snapshot\" node index.js"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}
  1. Create a simple index.js script
console.log('Hello World')
  1. Add a breakpoint to your console.log
  2. Run npm start in Debug mode. The breakpoint will work
  3. Run npm start-no-snapshot in Debug Mode. The code will run, but no breakpoints will bind.

It is possible to debug with --no-node-snapshot IF i use --inspect-brk, and then Attach to Process. When I do that, I can debug the process even with --no-node-snapshot.

Traces

Traces of when running the normal process:

Verbose logs are written to:
/home/node/.vscode-server/data/logs/20241025T202720/exthost2/ms-vscode.js-debug/vscode-debugadapter-749c4983.json.gz
/usr/local/bin/npm start
runtime.launch Bootloader imported {
  env: {
    inspectorIpc: '/tmp/node-cdp.2598-829b6388-9.sock',
    deferredMode: false,
    waitForDebugger: '',
    execPath: '/usr/local/bin/node',
    onlyEntrypoint: false,
    verbose: true,
    autoAttachMode: 'always',
    mandatePortTracking: true,
    fileCallback: '/tmp/node-debug-callback-800ea730dae14384'
  },
  args: [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
}
runtime Set debug mode { mode: 0 }
Debugger attached.

> sandbox@1.0.0 start
> node index.js

runtime.launch Bootloader imported {
  env: {
    inspectorIpc: '/tmp/node-cdp.2598-829b6388-9.sock',
    deferredMode: false,
    waitForDebugger: '',
    execPath: '/usr/local/bin/node',
    onlyEntrypoint: false,
    verbose: true,
    autoAttachMode: 'always',
    mandatePortTracking: true,
    openerId: '4c1bab8095dd988d9018b069'
  },
  args: [ '/usr/local/bin/node', '/workspaces/vscode/sandbox/index.js' ]
}
runtime Set debug mode { mode: 0 }
Debugger attached.
Hello, world!
2
Waiting for the debugger to disconnect...

Traces for when running with --no-node-snapshot

Verbose logs are written to:
/home/node/.vscode-server/data/logs/20241025T202720/exthost2/ms-vscode.js-debug/vscode-debugadapter-384a28de.json.gz
/usr/local/bin/npm run start-no-snapshot
runtime.launch Bootloader imported {
  env: {
    inspectorIpc: '/tmp/node-cdp.2598-957b5608-19.sock',
    deferredMode: false,
    waitForDebugger: '',
    execPath: '/usr/local/bin/node',
    onlyEntrypoint: false,
    verbose: true,
    autoAttachMode: 'always',
    mandatePortTracking: true,
    fileCallback: '/tmp/node-debug-callback-361c66c988144d9a'
  },
  args: [
    '/usr/local/bin/node',
    '/usr/local/bin/npm',
    'run',
    'start-no-snapshot'
  ]
}
runtime Set debug mode { mode: 0 }
Debugger attached.

> sandbox@1.0.0 start-no-snapshot
> NODE_OPTIONS="--no-node-snapshot" node index.js

Hello, world!
Waiting for the debugger to disconnect...

Here is 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": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Normal",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "start"
            ],
            "skipFiles": [
                "<node_internals>/**"
            ],
            "trace": true,
            "outputCapture": "std"
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Without Node snapshot",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run",
                "start-no-snapshot"
            ],
            "skipFiles": [
                "<node_internals>/**"
            ],
            "trace": true,
            "outputCapture": "std"
        },
    ]
}
connor4312 commented 3 weeks ago

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

sonikro commented 3 weeks ago

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

Damn that was a fast reply. That was exactly the problem. I failed to realize that by overriding NODE_OPTIONS, it would impact the Node debugger.

Changed it to:

NODE_OPTIONS=\"$NODE_OPTIONS --no-node-snapshot\"

And the debugger is working again as intended.

Thanks