Debugging 使用visual studio代码调试yeoman“;无法启动程序…”;

Debugging 使用visual studio代码调试yeoman“;无法启动程序…”;,debugging,yeoman,visual-studio-code,Debugging,Yeoman,Visual Studio Code,我试图在visual studio代码中调试yeoman生成器,但它一直告诉我它无法启动程序d:\repos\generator\node_modules\.bin\yo';每次我按F5键时启用源地图可能会有所帮助 我的VS代码配置文件如下所示: { "version": "0.1.0", "configurations": [ { // Name of configuration; appears in the launch config

我试图在visual studio代码中调试yeoman生成器,但它一直告诉我它
无法启动程序d:\repos\generator\node_modules\.bin\yo';每次我按F5键时启用源地图可能会有所帮助

我的VS代码配置文件如下所示:

{
    "version": "0.1.0",
    "configurations": [
        {
            // Name of configuration; appears in the launch configuration drop down menu.
            "name": "Launch app/index.js",
            // Type of configuration. Possible values: "node", "mono".
            "type": "node",
            // Workspace relative or absolute path to the program.
            "program": "node_modules/.bin/yo",
            // Command line arguments passed to the program.
            "args": [ "design" ],
            // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
            "cwd": ".",
            // 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": false,
            // If JavaScript source maps are enabled, the generated code is expected in this directory.
            "outDir": null
        }
    ]
}
{
    "name": "generator-design",
    "version": "0.1.0",
    "main": "app/index.js",
    "files": [
        "generators/app"
    ],
    "dependencies": {
        "yeoman-generator": "^0.20.3",
        "yosay": "^1.0.5",
        "chalk": "^1.1.1",
        "uuid": "^2.0.1",
        "yeoman-option-or-prompt": "^1.0.2"
    }
}
我的package.json是这样的:

{
    "version": "0.1.0",
    "configurations": [
        {
            // Name of configuration; appears in the launch configuration drop down menu.
            "name": "Launch app/index.js",
            // Type of configuration. Possible values: "node", "mono".
            "type": "node",
            // Workspace relative or absolute path to the program.
            "program": "node_modules/.bin/yo",
            // Command line arguments passed to the program.
            "args": [ "design" ],
            // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
            "cwd": ".",
            // 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": false,
            // If JavaScript source maps are enabled, the generated code is expected in this directory.
            "outDir": null
        }
    ]
}
{
    "name": "generator-design",
    "version": "0.1.0",
    "main": "app/index.js",
    "files": [
        "generators/app"
    ],
    "dependencies": {
        "yeoman-generator": "^0.20.3",
        "yosay": "^1.0.5",
        "chalk": "^1.1.1",
        "uuid": "^2.0.1",
        "yeoman-option-or-prompt": "^1.0.2"
    }
}
路径是正确的,yeoman正在工作,因为当我将其复制到命令行时,yeoman向我打招呼并询问我要运行哪个生成器。如果我选择了它,生成器也可以正常工作

  • VS代码版本为0.9.2
  • 操作系统是Windows
    8.1
  • Yeoman ist
    最新版本
我错过了什么

不确定这是否相关,但当我向yo文件添加.js时,VS代码会启动控制台(当然会失败,但至少控制台会启动)
如果我指向错误的路径,则错误消息将更改为
程序“d:\foo\bar\yo”不存在

要在Visual studio代码中调试Yeoman应用程序,必须提供
cli.js
路径,而不是yo路径

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "node",
            "request": "launch",
            "program": "<global path to yo>/node_modules/yo/lib/cli.js",
            "stopOnEntry": false,
            "args": [
                "yourGeneratorName"
            ],
            "cwd": "${workspaceRoot}",
            "preLaunchTask": null,
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "externalConsole": false,
            "sourceMaps": false,
            "outDir": null
        }
    ]
}

建议放置一个
调试器停止程序流并等待附加的指令。

在最新版本的Visual Studio代码(我使用1.16.1)中,可以通过“添加配置”直接添加Node.js调试配置

然后您只需编辑生成器名称。正如Max已经提到的,程序路径必须是
yo/lib
文件夹中的
cli.js
。您可以按照描述找到路径


当您启动生成器时,将启动一个内部终端,这样您就可以与问题提示进行交互(
“控制台”:“integratedTerminal”

我在尝试调试vscode中用typescript编写的yeoman生成器时偶然发现了这个问题

虽然这不是最初的问题,但我想我会把它贴在这里,以防其他人也有兴趣这么做

要调试typescript/yeoman模板,您需要修改vscode提供的默认启动配置,如下所示。 其中debug out只是一个测试输出目录

{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
  "version": "0.2.0",
  "configurations": [
    {
      // Debug Yeoman generator written in typescript
      "name": "Debug Generator",
      "runtimeArgs": ["${workspaceFolder}/node_modules/yo/lib/cli.js"],
      "program": "${file}",
      "cwd": "${workspaceFolder}/debug-out",
      "request": "launch",
      "type": "pwa-node",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "skipFiles": [
        "<node_internals>/**"
      ],
    },
  ]
}
{
//使用IntelliSense找出存在哪些用于C#调试的属性
//使用悬停来描述现有属性
//欲了解更多信息,请访问https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
“版本”:“0.2.0”,
“配置”:[
{
//调试用typescript编写的Yeoman生成器
“名称”:“调试生成器”,
“runtimeArgs”:[“${workspaceFolder}/node_modules/yo/lib/cli.js”],
“程序”:“${file}”,
“cwd”:“${workspaceFolder}/debug out”,
“请求”:“启动”,
“类型”:“pwa节点”,
“控制台”:“集成终端”,
“internalConsoleOptions”:“neverOpen”,
“滑雪板”:[
"/**"
],
},
]
}

调试生成器,例如,这样可以工作:-只是不在VS CodeHi Max中,我目前不再使用生成器,但我会在重新访问它后尝试一下。这适用于所有节点脚本还是仅适用于yeoman?您好,VIsual Studio代码集成了nodejs调试工具。附加方法适用于需要附加到辅助进程的任何节点pgm。“使用此系统,您无法回答任何问题”:如何将
externalConsole
设置为
true
?它不是解决了这个问题吗?而且,说到第一个代码:我能以某种方式更改起始目录吗?当我开始调试生成器时,它希望在我的yeoman项目目录中生成代码。它弄得一团糟…有人这样做吗?我试图使用它,但我似乎不能让它不覆盖工作目录。我尝试过制作workdirs和更改cwd,但当我开始调试时,它似乎仍然将生成器的输出写入git工作目录。