vscode无法启动节点应用

时间:2017-03-16 01:41:39

标签: node.js typescript visual-studio-code launch

我正在尝试使用Visual Studio Code& amp设置基于打字稿的快递应用程序工作流程。咽。

继承我的项目结构:

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

执行以下命令序列,我可以编译&amp;在集成终端中启动我的应用程序:

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

此时,我可以使用默认的“attach to process”命令成功附加到我的应用程序(它甚至可以正确地击中打字稿文件中的断点,是的!):

{
    "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 undefined中的shell.ts:426

通过Google搜索错误,我遇到了this bug

这个错误是什么意思?它有什么解决方法吗?我该怎么办?

2 个答案:

答案 0 :(得分:1)

小事总是会引起最大的问题。

问题是我选择了“附加到进程”任务(在调试模式下拉列表中)而不是“启动程序”任务。因此,当我按下F5时,vscode尝试附加到已经运行的进程而不是启动新进程。

** **捂脸

答案 1 :(得分:0)

我无法告诉你这个bug意味着什么,但是下面我将举例说明在类似环境中适合我的启动配置:

    {
        // 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。

希望这可以提供帮助。