Search code examples
debuggingyeomanvisual-studio-codeyeoman-generator

Debugging custom Yeoman generator using VSCode


Having a devil of a time getting VSCode to debug a custom Yeoman generator I'm working on.

The Yeoman docs say to execute the generator like this:

node --debug `which yo` <generator> [arguments]

I got this working using node-inspector. I start node-inspector in one terminal window, then in another window I do the above & when I launch the browser with the node-inspector site, I can attach and hit a breakpoint in my yeoman generator's script.

Now I'm trying to set this up using VSCode. I don't need node-inspector here... so I setup a a launch configuration that looks like this:

{
    // Name of configuration; appears in the launch configuration drop down menu.
    "name": "Launch yeoman generator-nodehttps",
    // Type of configuration. Possible values: "node", "mono".
    "type": "node",
    // Workspace relative or absolute path to the program.
    "program": "/Users/ac/.npm-packages/lib/node_modules/yo/lib/cli.js",
    // Automatically stop program after launch.
    "stopOnEntry": false,
    // Command line arguments passed to the program.
    "args": ["nodehttps"],
    // 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,
    // Environment variables passed to the program.
    "env": { }
}

The reason my program property is different is because putting which yo (in single quotes or not quoted) yielded an error from VSCode that "which yo does not exist

It successfully launches a new terminal window & I can interact with the generator, but none of my breakpoints are getting hit nor do I see anything showing up in the VSCode call stack / variables window... but VSCode appears attached to the process (orange bar at the bottom of the editor).

But no matter what I tweak, I can't seem to get VSCode to debug my generator... ideas?


Solution

  • running 'which yo' results in '/usr/local/bin/yo'. I suggest to use this for the 'program' attribute. In addition set 'stopOnEntry' to true so that you can see what is going on. For me debugging yo with VSCode worked with this launch config:

    {
        "name": "yo",
        "type": "node",
        "program": "/usr/local/bin/yo",
        "args": ["nodehttps"],
        "stopOnEntry": true
    }