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

Created on 10 May 2017  路  22Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.12.1
  • OS Version: Windows 7 Pro 64 bits
  • NodeJs Version: 6.10.0

Since the last update of vscode (1.12.1), when debugging my typescript/nodejs application (with nodemon), I got the error:

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

The same code/project works very well (without any changes) in the previous version of vscode (1.11.2).

But what is strange, is that the code still working in the background..My functions and other stuff are well executed...but I can't break on any breakpoints and I can't stop/start/pause the debugging process (with Play/Pause/Stop buttons that appears on the top when we start debugging) because buttons for doing that are not visible anymore. So no break on breakpoints, no debug buttons but code still running in the background.

As I said, I didn't change anything in my code or in my project/debug configuration.

Here is my launch.json config:

{
  // 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 server with Nodemon",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
      "runtimeArgs": [
        "--debug=5858"
      ],
      "program": "${workspaceRoot}/src/server.ts",
      "restart": true,
      "port": 5858,
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "outFiles": ["${workspaceRoot}/build/**/*.js"],
      "sourceMaps": true
    },
    {
      "type": "node",
      "request": "attach",
      "name": "Attacher au processus",
      "address": "localhost",
      "port": 5858,
      "outFiles": []
    }
  ]
}

As I said before, the same code with the same launch.json config works very well with vscode 1.11.2 when debugging with nodemon.

Can you help me please with this issue ?

Thank you for your answers..

debug

Most helpful comment

Most likely this is not an error, but you didn't notice the following in the VS Code 1.14 release notes:

In this release, Node.js debugging will assume the "inspector" protocol whenever the runtimeExecutable attribute of a launch configuration is set. If you see your debug configurations failing, this change could be the reason. To fix this, you can either upgrade Node.js to version 8.x or you can explicitly force the use of the "legacy" protocol by adding "protocol": "legacy" to your launch configuration.

and you might be interested in this improvement too: https://code.visualstudio.com/updates/v1_14#_simplified-setup-for-restart-debug-session

Combining both, your launch config should look like this:

{
    "type": "node",
    "request": "launch",
    "protocol": "legacy", 
    "name": "nodemon",
    "runtimeExecutable": "nodemon",
    "program": "${workspaceRoot}/src/server.js",
    "restart": true,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
}

After upgrading to node.js v8.x you can remove the "protocol": "legacy".

All 22 comments

@TitaneBoy does it make a difference if you set the "protocol" attribute to "legacy" instead of "inspector"?

@weinand It looks that everything works well, like before...No error message from vscode of the top and I can break on breakpoints.

Does it mean that "legacy" value must be used for Nodejs version below 8.0 ?

@TitaneBoy ohh, I think I know what the problem is: you are setting "protocol" to "inspector" but you are using the "--debug" flag at the same time. This cannot work. Are sure sure that this has worked before?

When setting "protocol" to "inspector" you have to use "--inspect=5858", when setting "protocol" to "legacy" you have to use "--debug=5858" .

You can use either "legacy" or "inspector" protocol for node version > 6.3 and < 8.0, but you have to make sure that you are using the matching "--debug" or "--inspect" argument.

BTW, this redundancy in the launch config will be fixed in the May release: you'll no longer have to specify a port at all, just the protocol will do the right thing.

@weinand Wow...Ok.. With your latest suggested changes, It looks to work well too (with "protocol" set to "inspector")

For your last question, yes I'm sure that this has worked before (with inspector protocol).

Thank you for your answer and quick support...:-)

It's great to know that we will no longer have to manage port. Does it means that the runtimeArgs in the launch.json will not be usefull anymore in the Max release ?

"runtimeArgs": [
    "--inspect=5858"
 ]


I guess that in my case (with nodemon), it will not...But of course, runtimeArgs will always be usefull...it depends of what we need to send and what executable we want to run...

Thanks again...:-)

If you are staying with the "legacy" protocol, then you should be able to drop the "port" and "runtimeArgs" attributes in tomorrows Insider release. For the "inspector" protocol we need some more time...

This error is back again, after updating to v1.14

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "nodemon",
            "runtimeExecutable": "nodemon",
            "runtimeArgs": [
                "--debug=5858"
            ],
            "program": "${workspaceRoot}/src/server.js",
            "restart": true,
            "port": 5858,
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen"
        }
    ]
}

Most likely this is not an error, but you didn't notice the following in the VS Code 1.14 release notes:

In this release, Node.js debugging will assume the "inspector" protocol whenever the runtimeExecutable attribute of a launch configuration is set. If you see your debug configurations failing, this change could be the reason. To fix this, you can either upgrade Node.js to version 8.x or you can explicitly force the use of the "legacy" protocol by adding "protocol": "legacy" to your launch configuration.

and you might be interested in this improvement too: https://code.visualstudio.com/updates/v1_14#_simplified-setup-for-restart-debug-session

Combining both, your launch config should look like this:

{
    "type": "node",
    "request": "launch",
    "protocol": "legacy", 
    "name": "nodemon",
    "runtimeExecutable": "nodemon",
    "program": "${workspaceRoot}/src/server.js",
    "restart": true,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
}

After upgrading to node.js v8.x you can remove the "protocol": "legacy".

@weinand I am on Node v8.1.4 and VS Code v1.14.0 and still need to add "protocol": "legacy".

@NiekPas I don't understand what you are trying to say with your statement. Is it a question?

@weinand Thanks for the previous comment, that did it for me.

@weinand You stated "After upgrading to node.js v8.x you can remove the "protocol": "legacy".", but this is not the case for me: if I don't add "protocol": "legacy"., I still get the error Cannot connect to runtime process, timeout after 10000ms - (reason: Cannot connect to the target: Parse Error)..

@NiekPas how does your launch config look like?

I am facing the same error, but the description is a bit different. Can you tell me whats wrong with my launch config. I am on VS Code 1.15.1 and running Node 7.4.0 on Ubuntu box. I get the following error -

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

launch.json file:

{
"version": "0.2.0",
  "configurations": [
    {
      "name": "Launch NPM",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "/usr/local/bin/npm",
      "runtimeArgs": [
        "run-script",
        "start"
      ],
      "protocol": "inspector",
      "console": "integratedTerminal"
    }
  ]
}

package.json file:

{
  "scripts": {
     "start": "nodemon ./start.js --inspect=5858 --ignore public/"
   }
}

I figured out what was the issue in my above config. Its a very silly issue. Node executable requires
--inspect flag before the filename. So accordingly, I changed my package.json file. I am pasting contents of my package.json below for reference.

{
  "scripts": {
     "start": "nodemon --inspect ./start.js --ignore public/"
   }
}

@tojochacko yes, that's a frequent pitfall...

I am using vscode version 1.16.1 and i am facing a similar problem. I am trying to create a vscode extension with typescript. And just by following the get started tutorial https://code.visualstudio.com/docs/extensions/example-hello-world i am able to run the extension but the program doesn't stop at any break point, also cant see the console.log in the debug console. This problem appeared after my last update.
My launch.json file looks like:

{
            "name": "Launch Extension",
            "type": "node"//v6.11.3, 
            "request": "launch",
            "runtimeExecutable": "${execPath}",
            "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
            "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
            "protocol": "legacy"
}

Does anyone have an idea to solve this please ?

The launch config is wrong.

Please always use a launch config generated by the latest version of the yeoman generator for code.

If you are using VS Code 1.16.1, your extension will use the builtin node.js version 7.9 (which only supports the "inspector" protocol). It doesn't matter what version of node you have installed. Extensions always use the builtin node.js.

In addition the "type" must be "extensionHost".

So this launch config should work:

{
            "name": "Launch Extension",
            "type": "extensionHost", 
            "request": "launch",
            "runtimeExecutable": "${execPath}",
            "args": [ "--extensionDevelopmentPath=${workspaceRoot}" ],
            "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ]
}

@weinand Thanks for your answer but the following launch config does not work and gives the error "Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms - (reason: Response from the target seems invalid"
I used a similar one when i generated the projet with "yo code generator".
Does the helloworld project work for you when you follow the tutorial with vscode 1.16.1 ? https://code.visualstudio.com/docs/extensions/example-hello-world ,because it is not the case for me...

Yes, the hello-world works for me.

I just did this:

npm install -g yo generator-code
yo code
cd testo
code .
F5

and everything worked like a charm.

If it doesn't work for you, try to run code without extensions and see whether that makes a difference.

Was this page helpful?
0 / 5 - 0 ratings