debugging - 使用 Visual Studio 代码 "cannot launch programm ..."调试自耕农

标签 debugging yeoman visual-studio-code

我正在尝试在 Visual Studio 代码中调试自耕农生成器,但它一直告诉我它 cannot launch programm d:\repos\generator\node_modules\.bin\yo'; enabling source maps might help每次我按F5

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

{
    "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
        }
    ]
}

我的 package.json 是这样的:
{
    "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
  • 自耕农 latest

  • 我在这里缺少什么?

    不确定这是否相关,但是当我将 .js 添加到 yo 文件时,VS Code 会启动控制台(当然它会失败,但至少控制台会启动)
    如果我指向错误的路径,错误消息将更改为 program 'd:\foo\bar\yo' does not exist

    最佳答案

    要在 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 Code 附加到进程

    node --debug "\npm\node_modules\yo\lib\cli.js" yourGeneratorName



    在您的 launch.json你必须有这样的条目
    {
                "name": "Attach",
                "type": "node",
                "request": "attach",
                "port": 5858,
                "address": "localhost",
                "restart": false,
                "sourceMaps": false,
                "outDir": null,
                "localRoot": "${workspaceRoot}",
                "remoteRoot": null
            }
    

    建议放置一个 debugger;停止程序流并等待附加代码的指令。

    关于debugging - 使用 Visual Studio 代码 "cannot launch programm ..."调试自耕农,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33395636/

    相关文章:

    deployment - 为什么 Yeoman 在没有字形的情况下构建?

    html - 安装 Nunjucks 扩展后设置 HTML 格式

    visual-studio-code - VSCode 搜索/转到定义

    php - PHP解析/语法错误;以及如何解决它们

    c - 使用 GDB 确定代码错误

    node.js - 如何定义 GruntJS 服务的内容?

    node.js - 使用 Yeoman/Grunt 设置 Jade 进行模板化的正确方法

    reactjs - 你如何在 vscode 中显示 react 组件 props 的预期值?

    c++ - "this"GDB 回溯中的指针变化

    c# - Visual Studio C# 2010 快速调试运行速度比发布快