首页 文章

vscode无法启动节点应用

提问于
浏览
3

我正在尝试使用Visual Studio Code和gulp设置基于打字稿的快速应用程序工作流程 .

继承我的项目结构:

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

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

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

但是, launching with F5 fails every time . 调试控制台上没有输出,几秒钟后我在顶部收到错误标语 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" ]
}

I tried opening the debug console . 每次我保存launch.json文件时,它都会给我以下错误: Cannot read property '_runner' of undefined: TypeError: Cannot read property '_runner' of undefined in shell.ts:426

谷歌搜索错误,我遇到了this bug

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

2 回答

  • 0

    小事总是引起最大的问题 .

    问题是我选择了"Attach to Process"任务(在调试模式下拉列表中)而不是"Launch Program"任务 . 所以,当我按 F5 时,vscode试图附加到已经运行的进程而不是启动一个新进程 .

    ** **捂脸

  • 1

    我无法告诉你这个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 .

    希望这可以提供帮助 .

相关问题