2017-12-18 352 views
0

我目前正在嘗試通過visual studio代碼來調試我的NodeJS應用程序。當我通過PowerShell運行程序時,我使用「npm start」運行它。當試圖在Visual Studio Code中調試應用程序時,我會在NodeJS內部文件中收到錯誤。這是我的配置文件是什麼樣子(這是默認提供的):在VS代碼中的NodeJS應用程序的調試配置中運行「npm start」

{ 
    "version": "0.2.0", 
    "configurations": [ 
     { 
      "type": "node", 
      "request": "launch", 
      "name": "Launch Program", 
      "program": "${workspaceFolder}\\server.js" 
     } 
    ] 
} 

試圖改變「計劃」,「故宮開始」不起作用。

回答

0

您可以使用啓動配置運行npm腳本,但您的npm腳本需要在調試模式下啓動節點。例如:

在的package.json:

"scripts": { 
    "start": "node --nolazy --inspect-brk=9229 server.js 
} 

launch.json:

{ 
    "version": "0.2.0", 
    "configurations": [ 
     { 
      "type": "node", 
      "request": "launch", 
      "name": "Launch Program", 
      "runtimeExecutable": "npm", 
      "runtimeArgs": [ "start" ], 
      "port": 9229 
     } 
    ] 
} 

,或者改變你的啓動配置做的正是whatver npm start在做什麼。

在啓動配置中使用'npm'的文檔:https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools

相關問題