1

當我在控制檯中鍵入npm run debug時,得到:"Debugger listening on ws://127.0.0.1:3090/d17dfe56-4fa4-4686-a62e-d07cff78c834"。當我用鉻版去這個地址時,我看到的唯一的東西是"WebSockets request was expected"。我應該調整配置的哪些部分以使調試器工作?我正在使用最新版本的nodejs。無法爲具有babel節點的節點啓動VSCode調試器

的package.json腳本

"scripts": { 
    "prod": "webpack -p --env.production --progress", 
    "start": "babel-node --presets es2015 server/server.js", 
    "watch": "nodemon --exec npm run start", 
    "debug": "babel-node --presets es2015 server/server.js --inspect --debug-brk=3090" 
    } 

launch.json:

{ 
    "version": "0.2.0", 
    "configurations": [ 
     { 
      "name": "Launch via NPM", 
      "type": "node", 
      "request": "launch", 
      "runtimeExecutable": "npm", 
      "program": "${workspaceRoot}/server/server.js", 
      "restart": true, 
      "runtimeArgs": [ 
       "run-script", "debug" 
      ], 
      "port": 3090 
     }, 
     { 
      "type": "chrome", 
      "request": "launch", 
      "name": "Launch Chrome against localhost", 
      "url": "http://localhost:3090", 
      "webRoot": "${workspaceRoot}" 
     }, 
     { 
      "type": "chrome", 
      "request": "attach", 
      "name": "Attach to Chrome", 
      "port": 3090, 
      "webRoot": "${workspaceRoot}" 
     } 
    ] 
} 

文件結構:

├───.vscode 
├───js 
├───server 
│ ├───db 
│ ├───middleware 
│ ├───models 
│ ├───server.js 

enter image description here

回答

3

這似乎是一個問題nodejs庫版本> = 7.0.0。

第一個解決方法:

一個小的解決方法在Chrome中打開此文件,開發工具是你的情況ws後鏈接的代碼複製:

Debugger listening on ws://127.0.0.1:3090/d17dfe56-4fa4-4686-a62e-d07cff78c834 

,並在其追加開發工具行的末尾與ws=鏈接,如下所示:

chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:3090/d17dfe56-4fa4-4686-a62e-d07cff78c834 

這將使您能夠使用chrome開發工具打開您的程序。 Link和解決問題給出here

第二種解決方法:

我嘗試安裝舊版本的節點即6.11.2和NPM 3.10並把它在Visual Studio代碼一試,這是工作完美罰款沒有任何問題。然而,用第一種方法顯示的技巧,我仍然可以使用節點和npm的最新版本。

編輯:格式化我的答案,以便更好地瞭解

+0

謝謝。我安裝了6.2版本的節點js,現在我從控制檯獲取了一個正確的URL。但是,chrome開發工具中的「sources」中不存在server.js文件。我的launch.json有問題嗎? – Umbrella

+0

考慮到您已經從工作空間位置運行您的項目,您可以嘗試更改'「程序」:「$ {workspaceRoot} /server/server.js」,使用'「program」:「$ {workspaceRoot}/server .js「,看看它是否在運行。 – Dhruvify

+0

不幸的是,「$ {workspaceRoot} /server.js」和「$ {workspaceRoot}」都不起作用。 – Umbrella