[英]Not able to attach debugger to already running nodejs web app on port 3000
我無法將調試器附加到已經運行的 NodeJS Web 應用程序。
以下是我的 VSCode 啟動配置:
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 3001
},
我收到以下錯誤消息:
無法連接到運行時進程(原因:此套接字已被對方終止)。
現在,當我在上面的配置中添加protocol : inspector
時,它顯示了以下錯誤消息:
確保使用 --inspect 啟動 Node。 無法連接到運行時進程,10000 毫秒后超時
我目前使用的是 v8.6.0 版本的 NodeJS
以下是我在 package.json >> 腳本中的配置:
"scripts": {
"start": "npm run build && npm run watch --inspect",
"build": "npm run build-sass && npm run build-ts && npm run tslint && npm run copy-static-assets",
"serve": "nodemon dist/server.js",
"watch": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve\"",
"test": "jest --forceExit",
"build-ts": "tsc",
"watch-ts": "tsc -w",
"build-sass": "node-sass src/public/css/main.scss dist/public/css/main.css",
"watch-sass": "node-sass -w src/public/css/main.scss dist/public/css/main.css",
"tslint": "tslint -c tslint.json -p tsconfig.json",
"copy-static-assets": "node copyStaticAssets.js",
"debug": "npm run build && npm run watch-debug",
"serve-debug": "nodemon --inspect dist/server.js",
"watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\""
},
做好了!
在指定腳本之前,您必須將其傳遞給服務。 此外,您需要在腳本中明確指定端口和 URL :
"serve": "nodemon dist/server.js",
將其更改為:
"serve": "nodemon --inspect=0.0.0.0:9229 dist/server.js",
當 URL 為0.0.0.0
而不是127.0.0.1
時,顯然 vscode 有效。
然后,在launch.json中:
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Docker: Attach to Node",
"port": 9229,
"restart": true,
"localRoot": "${workspaceFolder}/src",
"remoteRoot": "./dist}
]
請注意我根據您向我展示的圖片放置的localRoot
和remoteRoot
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.