简体   繁体   English

调试〜10秒后,Visual Studio代码nodemon ECONNREFUSED

[英]Visual Studio Code nodemon ECONNREFUSED after ~10 s of debugging

I created a test project using npm init and installed TypeScript. 我使用npm init创建了一个测试项目并安装了TypeScript。 Now I want Visual Studio to use nodemon for live re-attach of our debugger. 现在我希望Visual Studio使用nodemon实时重新连接我们的调试器。 According to the doc, it was installed globally using npm install -g nodemon . 根据该文档,它使用npm install -g nodemon全局npm install -g nodemon Now I see the template when trying to add a new launch.json configuration and the following config was added: 现在我在尝试添加新的launch.json配置时看到了模板,并添加了以下配置:

{
    "type": "node",
    "request": "launch",
    "name": "nodemon",
    "runtimeExecutable": "nodemon",
    "program": "${workspaceFolder}/dist/index.js",
    "restart": true,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
}

I also tried to go directly on the typescript files by using 我也试着通过使用直接去打字稿文件

"program": "${workspaceFolder}/index.ts",
"outFiles": [
     "${workspaceRoot}/dist/*.js"
 ]

The debugging works, breakpoints were reached. 调试工作,达到了断点。 But it has a big problem: After about ~10 seconds of debugging, I get the following error message: 但是它有一个很大的问题:经过大约10秒的调试后,我收到以下错误信息:

Cannot connect to runtime process, timeout after 10000ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:30792.) 无法连接到运行时进程,10000ms后超时 - (原因:无法连接到目标:连接ECONNREFUSED 127.0.0.1:30792。)

What's the problem here? 这有什么问题? I exactly followed the documentation but couldn't make it work properly. 我完全按照文档,但无法使其正常工作。

I only found some topics about old NodeJS versions in legacy mode. 我只在遗留模式下找到了一些关于旧NodeJS版本的主题。 But I'm using a new one (v8.9.4) on Windows 7. 但是我在Windows 7上使用了新的(v8.9.4)。

Had the same error and took me a while to solve it, here's my settings which eventually worked. 有同样的错误,并花了我一段时间来解决它,这是我的设置,最终工作。

package.json 的package.json

 "scripts": {
    "start": "node --inspect -r ts-node/register src/server.ts",
    "dev": "./node_modules/nodemon/bin/nodemon.js",
    "test": "jest",
    "test:watch": "jest --watch"
  }

nodemon.json nodemon.json

{
    "ignore": ["**/*.test.ts", "**/*.spec.ts", ".git", "node_modules"],
    "watch": ["src"],
    "exec": "npm start",
    "ext": "ts, gql",
    "inspect": true,
    "events": {
        "restart": "echo \"[Warning] Remember run npm run test b4 push to dev branch !\""
    }
}

launch.json launch.json

{
 "version": "0.2.0",
    "configurations": [{
        "type": "node",
        "request": "attach",
        "name": "Attach to Process",
        "port": 9229,
        "restart": true,
        "protocol": "inspector",
        // "processId": "${command:PickProcess}",
        "address": "localhost"
    }]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM