VS Code debug port mismatch

Viewed 1173

Details

In Win10. VS Code, Help, About...

[Window Title]
Visual Studio Code

[Content]
Version 1.14.2
Commit cb82febafda0c8c199b9201ad274e25d9a76874e
Date 2017-07-19T23:34:09.706Z
Shell 1.6.6
Renderer 56.0.2924.87
Node 7.4.0

Generated launch.json, adjusted with my runtime... settings

{
    // Use IntelliSense to learn about possible Node.js debug 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 Program",
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "npm.cmd",
            "runtimeArgs": [
                "run", "functional-test"
            ],
            "skipFiles": [
                "<node_internals>/**/*.js"
            ]
        }
    ]
}

Npm script referenced above...

"functional-test": "node test/functional/run-foo-tests",

First attempt

I then launch a debug session (F5), which in the Debug Console then yields...

Debugging with inspector protocol because a runtime executable is set.
npm.cmd --inspect=32825 --debug-brk run functional-test

Note the additional flags that aren't specified anywhere in my package.json or launch.json.

In addition to that message above, I am shown a popup in the IDE referencing a connection timeout error...

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED

Second attempt

If I change the npm script as follows (include --inspect flag)...

"functional-test": "node --inspect test/functional/run-foo-tests",

The Debug Console states...

Debugging with inspector protocol because a runtime executable is set.
npm.cmd --inspect=17976 --debug-brk run functional-test
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.

Note different port settings. At least the debugger is starting and giving me a port to try and target instead.

Where is it getting those values? How can I make them match (without manually editing both launch.json and npm script to assign the same port for both)?

It never successfully loads and instead I am shown the popup message at the top (mentioned above.)

Third attempt

If I edit the npm script to add the port...

"functional-test": "node --inspect=9229 test/functional/run-foo-tests",

And edit launch.json's port setting to match...

"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "cwd": "${workspaceRoot}",
        "runtimeExecutable": "npm.cmd",
        "runtimeArgs": [
            "run", "functional-test"
        ],
        "port": 9229,
        "skipFiles": [
            "<node_internals>/**/*.js"
        ]
    }
]

I then am rewarded with the following message in the Debug Console...

Debugging with inspector protocol because a runtime executable is set.
npm.cmd run functional-test
Debugger listening on port 5858.
Warning: This is an experimental feature and could change at any time.
{Expected console output...}

It will then work correctly (AFAIK!) Note that now the Debug Console's second line (echoing/logging the command ran) now matches the launch.json runtimeArgs settings (where it did not in the first and second attempts.)

Aside from skull-smashing brute force of trial and error, how was one supposed to figure this out (and surely there must be a better way?)

Fourth attempt

Trying to set the port both for the npm script call (obviously not the same as the node ... call in the npm script) and the port config param and it fails as in the first example.

"runtimeArgs": [
    "run", "functional-test", "--inspect=5858"
],
"port": 5858,

Fifth attempt

Of course, as I was writing this, I finally found something like an answer via google...

"scripts": {
    "debug": "node --nolazy --debug-brk=5858 myProgram.js"
},

Adjusting my script to match yields (in Debug Console)...

Debugging with inspector protocol because a runtime executable is set.
npm.cmd run functional-test
(node:12420) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead.
Debugger listening on 127.0.0.1:5858

I am also shown a different popup at the top...

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: Parse Error).

Sixth attempt

If I change my script to match the info in the Debug Console...

"functional-test": "node --nolazy --inspect test/functional/run-foo-tests",

Debug Console says...

Debugging with inspector protocol because a runtime executable is set.
npm.cmd run functional-test
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.

And popup is...

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1

0 Answers
Related