Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got Node process error: Error: spawn npm ENOENT when debug node.js #31433

Closed
dxcqcv opened this issue Jul 26, 2017 · 5 comments
Closed

Got Node process error: Error: spawn npm ENOENT when debug node.js #31433

dxcqcv opened this issue Jul 26, 2017 · 5 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@dxcqcv
Copy link

dxcqcv commented Jul 26, 2017

  • VSCode Version: 1.14.2
  • OS Version: windows 7
  • node.js Version: 7.6.0

Steps to Reproduce:

  1. F5

Reproduces without extensions: No

===================

I try to debug node.js in VScode, then get error is

    npm run-script server 
    Node process error: Error: spawn npm ENOENT

, and my launch.json is:

{
  // 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 via NPM",
      "runtimeExecutable": "npm",
      "protocol": "inspector",
      "runtimeArgs": [
        "run-script",
        "server"
      ],
      "port": 5858
    }
  ]
}

and if I change protocol to legacy, I'll get another error

    Unable to connect to the runtime through the "legacy" protocol; Consider using the "inspector" protocol (timeout after 10,000 milliseconds).
@vscodebot vscodebot bot added the debug Debug viewlet, configurations, breakpoints, adapter issues label Jul 26, 2017
@bigteejay
Copy link

bigteejay commented Aug 2, 2017

I am getting the same error, on Win10.

Contents of Help/About...

[Window Title]
Visual Studio Code
[Content]
Version 1.14.2
Commit cb82feb
Date 2017-07-19T23:34:09.706Z
Shell 1.6.6
Renderer 56.0.2924.87
Node 7.4.0

This is on a fresh install of VSCode, with no extensions or settings changes at all (simply loaded the project root folder that I am trying to debug.)

However, since I have been running my script manually using...

> npm run functional-test

...from my project root (without issues otherwise) I thought I would adjust the the launch.json file's runtimeArgs property to...

            "runtimeArgs": [
                "run", "functional-test"
            ],

...hoping the solve the problem that seemed to indicate it can't find an executable/script.

Yet I get exactly the same error as OP posted in the "DEBUG CONSOLE"...

Debugging with inspector protocol because a runtime executable is set.
npm run functional-test
Node process error: Error: spawn npm ENOENT

There is no information in either the "PROBLEMS" or "OUTPUT" tabs.

@bigteejay
Copy link

I was able to fix this problem (as outlined here) by changing the runtimeExecutable to instead target the Windows executable for npm (npm.cmd) by editing the launch.json as...

   "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "npm.cmd",
            "runtimeArgs": [
                "run", "functional-test"
            ],
            "port": 5858
        }
    ]

However, now I am seeing the following error message (which I am guessing is a different issue.)

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

@weinand weinand assigned roblourens and unassigned weinand Aug 18, 2017
@roblourens
Copy link
Member

Missing npm.cmd is my fault, it's supposed to be picked up automatically and I didn't port all the required changes from vscode-node-debug.

In the second case, Cannot connect to runtime process... make sure that your npm script sets the --inspect-brk=port flag. The docs describe this - https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools although they mention the old --debug flag instead. PR to fix that is in progress: microsoft/vscode-docs#1127

@bigteejay
Copy link

@roblourens - The referenced docs point us to, "--debug-brk", but your input above indicates we should use "--inspect-brk=port". Which should we use and why?

Also, am I missing anything or is there an easy way to coordinate the port setting in launch.json vs package.json npm scripts?

@roblourens
Copy link
Member

--debug-brk starts node using their "legacy" debug protocol, which isn't available after Node 8. --inspect-brk starts it with the new "inspector" protocol, which is available after roughly Node 6.5. In between, you could use either one, and vscode should detect it. I recommend using --inspect-brk so it won't break if you upgrade to Node 8.

One way to make it a little less redundant is to rely on the default ports - --inspect-brk alone will use port 9229.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

5 participants