Skip to content

Debugger setup tuning for using VS Code with the mern.io starter kit #22378

Closed

Description

@egamma

// CC Chris Dias (@chrisdias)

http://mern.io/ defines a starter kit for MERN. I was looking with Andre Weinand (@weinand) into the best VS Code debugger setup.

The idea is to use an NPM launch configuration so that the vscode independent launching details can be defined inside the package.son and do not have to be defined inside the vscode specific launch configuration.

I've added the following script to the starter kit's package.json in the scripts section:

"start:debug": "cross-env BABEL_DISABLE_CACHE=1 NODE_ENV=development nodemon --nolazy --inspect=5858 index.js",

With the following launch configuration we could launch and debug the target from VS Code.

The script sets restart to true since the starterkit is using nodemon and we want to reattach when nodemon restarts the target program.

        {
            "name": "Launch via NPM",
            "type": "node",
            "request": "launch",
            "protocol": "inspector",
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "npm",
            "windows": {
                "runtimeExecutable": "npm.cmd"
            },
            "runtimeArgs": [
                "run-script",
                "start:debug"
            ],
            "timeout": 20000,
            "restart": true,
            "port": 5858
        }

We've ran into the following glitches:

  • using the inspector protocol worked but we did not see all the console output (e.g. the webpack built time) in the DebugConsole.
  • when using the legacy protocol and the --debug option you get a timeout error.
  • with the working setup above you need to use the task manager to kill the target program. We tried to configure the launch configuration to use the internal terminal so that we can kill the target from the terminal. When using the internal terminal then the launching failed.

Activity

  1. weinand commented on Mar 15, 2017

    @weinand
    Contributor

    Issue 3 from above is the result of a changed API. See #22409 for details. It is fixed in the Insiders by now.

  2. chrisdias commented on Mar 15, 2017

    @chrisdias
    Contributor

    Perhaps we can make a variant of the mern-starter that includes the launch.json and updated package.json, then make a PR on the mern-cli. See "make your mern" at http://mern.io/ .

  3. chrisdias commented on Mar 27, 2017

    @chrisdias
    Contributor

    added

    "console": "integratedTerminal"

    And was able to launch the app under the debugger. However, I could only ever get it to hit a breakpoint one time.

  4. michelkaporin commented on Apr 7, 2017

    @michelkaporin
    Contributor

    FYI When using legacy protocol with --debug-brk instead of --debug option, debugger could successfully attach and run MERN but some of the breakpoints could not be hit (e.g. index.js was hit, post.controller.js not). Debugger was also stopping its execution (Continue action became enabled) with no UI indication where it has stopped.

  5. michelkaporin commented on Apr 7, 2017

    @michelkaporin
    Contributor

    Closing the issue as:

    • webpack built time is shown in the console output (Windows/Mac verified).
    • using node legacy protocol is tricky because babel-register is used, which compiles files on the fly when require() is called. This complicates much the legacy protocol to get access to the dynamically compiled files.
    • launching through integrated terminal works fine, breakpoints can be hit many times (Windows/Mac verified).
  6. chrisdias commented on Apr 7, 2017

    @chrisdias
    Contributor

    Michel Kaporin (@michelkaporin) thanks for the update!

    I'm reopening this because I don't know what to do as a user still :) Imagine I'm new to VS Code and I'm learning MERN. I read our docs and press F5 and nothing seems to work. What do I do?

    Our model is to configure the launch.json in such a way that F5 just works. The suggestion above to launch through the integrated terminal sounds like a workaround?

    My question then is, what is the proper setup in VS Code to get debugging to just work here, and how can we make that easier?

  7. 10 remaining items

  8. removed
    bugIssue identified by VS Code Team member as probable bug
    on Apr 9, 2017
  9. weinand commented on Apr 10, 2017

    @weinand
    Contributor

    The automatically generated launch config assumes that "nodemon" is installed globally.
    This assumption can be removed as soon as microsoft/vscode-node-debug2#98 has been addressed.

  10. chrmarti commented on Apr 27, 2017

    @chrmarti
    Collaborator

    --inspect seems to be missing, the debugger fails to attach:

    screen shot 2017-04-27 at 11 19 44 am

    Adding "runtimeArgs": [ "--inspect=5858" ] to the generated launch config makes it work out-of-the-box (assuming MongoDB is running...).

  11. chrmarti commented on Apr 27, 2017

    @chrmarti
    Collaborator

    Btw., I'm still asked for the environment before the generated launch is used, is that by design?

  12. weinand commented on Apr 28, 2017

    @weinand
    Contributor

    I've added the "runtimeArgs": [ "--inspect=5858" ].

  13. weinand commented on May 9, 2017

    @weinand
    Contributor

    A first cut of a "MERN Recipe" is available here: https://github.com/weinand/vscode-recipes/tree/master/MERN-Starter

  14. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debugDebug viewlet, configurations, breakpoints, adapter issuesfeature-requestRequest for new features or functionalityverification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions