node.js – 调试〜10秒后Visual Studio代码nodemon ECONNREFUSED

我使用npm init创建了一个测试项目并安装了TypeScript.现在我希望Visual Studio使用nodemon实时重新连接我们的调试器.根据该文档,它使用npm install -g nodemon全局安装.现在,我在尝试添加新的launch.jsonconfiguration时看到了模板,并添加了以下配置:

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

我也试着通过使用直接去打字稿文件

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

调试工作,达到了断点.但是它有一个很大的问题:经过大约10秒的调试后,我收到以下错误信息:

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

这有什么问题?我完全遵循documentation但无法使其正常工作.

我只在遗留模式下找到了一些关于旧NodeJS版本的主题.但是我在Windows 7上使用了新的(v8.9.4).

最佳答案 有同样的错误,并花了我一段时间来解决它,这是我的设置,最终工作.

的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

{
    "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

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