经过大约 10 秒的调试后,Visual Studio Code nodemon ECONNREFUSED [英] Visual Studio Code nodemon ECONNREFUSED after ~10 s of debugging
问题描述
我使用 npm init
创建了一个测试项目并安装了 TypeScript.现在我希望 Visual Studio 使用 nodemon
来实时重新附加我们的调试器.根据文档,它是使用 npm install -g nodemon
全局安装的.现在我在尝试添加新的 launch.json
配置时看到了模板,并添加了以下配置:
I created a test project using npm init
and installed TypeScript. Now I want Visual Studio to use nodemon
for live re-attach of our debugger. According to the doc, it was installed globally using npm install -g nodemon
. Now I see the template when trying to add a new launch.json
configuration and the following config was added:
{
"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"
]
调试成功,达到断点.但它有一个大问题:调试大约 10 秒后,我收到以下错误消息:
The debugging works, breakpoints were reached. But it has a big problem: After about ~10 seconds of debugging, I get the following error message:
无法连接到运行时进程,10000 毫秒后超时 - (原因:无法连接到目标:connect ECONNREFUSED 127.0.0.1:30792.)
Cannot connect to runtime process, timeout after 10000ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:30792.)
这里有什么问题?我完全按照 documentation 但没能做到正常工作.
What's the problem here? I exactly followed the documentation but couldn't make it work properly.
我只找到了一些关于遗留模式下旧 NodeJS 版本的主题.但是我在 Windows 7 上使用了一个新的 (v8.9.4).
I only found some topics about old NodeJS versions in legacy mode. But I'm using a new one (v8.9.4) on Windows 7.
推荐答案
遇到了同样的错误,我花了一段时间才解决,这是我最终成功的设置.
Had the same error and took me a while to solve it, here's my settings which eventually worked.
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"
}]
}
这篇关于经过大约 10 秒的调试后,Visual Studio Code nodemon ECONNREFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!