2017-03-16 63 views
3

我正嘗試使用Visual Studio代碼& gulp設置基於打印腳本的快速應用程序工作流程。vscode無法啓動節點應用程序

繼承人我的項目結構:

src/ <-- souce files 
    Start.ts 
    Server.ts 
    models/ 
    Contact.ts 
    Organization.ts 
bin/ <-- compiled output 
    Start.js 
    Start.js.map 
    ... 
tsconfig.json 
gulpfile.json 
package.json 
.vscode/ 
    launch.json 

執行下面的命令序列,我可以編譯&啓動我的應用程序中集成終端:

> tsc 
> node --debug-brk ./bin/Start.js 

在這一點上,我可以成功連接到我的應用程序使用默認的「attach to process」命令(並且它甚至在打字稿文件中正確輸入斷點,yeyy!):

{ 
    "type": "node", 
    "request": "attach", 
    "name": "Attach to Process", 
    "address": "localhost", 
    "port": 5858 
} 

但是,F5一起啓動失敗每次。目前在調試控制檯沒有輸出,並在幾秒鐘內我會在頂部的錯誤橫幅,上面寫着Cannot connect to runtime via 'legacy' protocol; consider using 'inspector' protocol (timeout after 10000 ms).

這裏是我的啓動配置(在launch.json):

{ 
    "type": "node", 
    "request": "launch", 
    "name": "Launch Program", 

    // Using compiled .js file. vscode should use the sourcemap to correlate 
    // with breakpoints in the source file 
    "program": "${workspaceRoot}/bin/Start.js", 
    "outFiles": [ "${workspaceRoot}/bin/**/*.js" ] 
} 

我試着開調試控制檯。每次我保存launch.json文件,它給了我下面的錯誤:Cannot read property '_runner' of undefined: TypeError: Cannot read property '_runner' of undefinedshell.ts:426

谷歌搜索的錯誤,我碰到this bug

來到那這個錯誤是什麼意思?有沒有解決方法?什麼哦,我該怎麼辦?

回答

1

小東西總是造成最大的問題。

問題是我選擇了「附加到進程」任務(在調試模式下拉菜單中),而不是「啓動程序」任務。所以,當我按F5時,vscode試圖連接到已經運行的進程而不是啓動一個新進程。

** facepalm **

0

我不能告訴你什麼是錯誤的手段,但低於我會給推出的配置,對於我在類似的環境到你的工作的一個例子:

{ 
     // Name of configuration; appears in the launch configuration drop down menu. 
     "name": "Launch Server", 
     // Type of configuration. 
     "type": "node2", 
     // Workspace relative or absolute path to the program. 
     "program": "${workspaceRoot}/server/app.ts", 
     // Automatically stop program after launch. 
     "stopOnEntry": false, 
     // Command line arguments passed to the program. 
     "args": [], 
     // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace. 
     "cwd": "${workspaceRoot}", 
     // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. 
     "runtimeExecutable": null, 
     // Optional arguments passed to the runtime executable. 
     "runtimeArgs": ["--nolazy"], 
     // Environment variables passed to the program. 
     "env": { 
      "NODE_ENV": "development" 
     }, 
     // Use JavaScript source maps (if they exist). 
     "sourceMaps": true, 
     "request": "launch", 
     "outFiles": [ 
      "${workspaceRoot}/dist/dev/*/*.js" 
     ]   
    } 

注意,被設置爲type的差異node2program指向ts而不是js。

希望這可以幫助。

+0

'node2'的意義是什麼? – Julien

+0

沒有什麼特別的:https://marketplace.visualstudio.com/items?itemName=ms-vscode.node-debug2它曾經幫助我處理'奇怪'的情況,但是如果你有最新的VSCode,那麼node2已經被棄用了並自動切換到:https://code.visualstudio.com/updates/v1_10#_node2-transitioning – Amid