Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
egamma opened this issue Mar 10, 2017 · 15 comments
Closed

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

egamma opened this issue Mar 10, 2017 · 15 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@egamma
Copy link
Member

egamma commented Mar 10, 2017

// CC @chrisdias

http://mern.io/ defines a starter kit for MERN. I was looking with @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.
@egamma egamma added the debug Debug viewlet, configurations, breakpoints, adapter issues label Mar 10, 2017
@weinand
Copy link
Contributor

weinand commented Mar 15, 2017

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

@chrisdias
Copy link
Member

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/ .

@chrisdias
Copy link
Member

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.

@weinand weinand added the bug Issue identified by VS Code Team member as probable bug label Apr 6, 2017
@weinand weinand added this to the April 2017 milestone Apr 6, 2017
@michelkaporin
Copy link
Contributor

michelkaporin commented Apr 7, 2017

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.

@michelkaporin
Copy link
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).

@michelkaporin michelkaporin added the verified Verification succeeded label Apr 7, 2017
@michelkaporin michelkaporin modified the milestones: March 2017, April 2017 Apr 7, 2017
@chrisdias
Copy link
Member

@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?

@chrisdias chrisdias reopened this Apr 7, 2017
@michelkaporin
Copy link
Contributor

@chrisdias The proper setup is described in the initial post here by @egamma, which works good and verified with respect to raised bullet points for this issue.

Regards the process simplifying I would propose to create a mern-starter kit for VS Code developers. As you pointed out we can do it with the help of "make your mern" at http://mern.io, where we can add the debug configuration listed above that works fine and enables a debugging for a user.

Doing auto-detection of MERN stack on F5 seems also a nice idea, although I don't know how this works now and how we can integrate it, maybe @weinand can give a light on it.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Apr 7, 2017

Once debugging is stopped, you see the below in the terminal:

[nodemon] app crashed - waiting for file changes before starting...

nodemon should exit when user exits the debug session

@weinand
Copy link
Contributor

weinand commented Apr 7, 2017

@chrisdias some comments:

We have verified that the proposed launch config (see below) works as expected: pressing F5 runs MERN's own "npm run start" but with debugging enabled. It takes some time (30 secs) until everything has been build and webpacked but in the end the user sees a "MERN is running on port: 8000! Build something amazing!"

The launch config has to use the integrated terminal because "npm run start" uses "nodemon" which is an interactive tool that reads from stdin (nodemon outputs: "to restart at any time, enter rs"). Reading from stdin is not supported in the debug console (REPL). So using the integrated terminal is not a workaround but recommended practice for interactive programs (see VS Code doc).

This is the definitive launch config (which relies on a new start:debug script in the package.json):

{
        "name": "Launch via NPM script",
        "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,
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen"
    }

We could try to detect MERN in the node extension and generate the launch config from above automatically, but I don't think that this approach is sustainable because we would have to track all changes in the underlying frameworks and adapt our launch config generation code frequently. A better approach is to let MERN maintain the launch config on their side.

There are two remaining issues (which are independent from MERN and are covered by separate issues):

@weinand weinand changed the title Debugger setup tuning for using VS Code with the mearn.io starter kit Debugger setup tuning for using VS Code with the mern.io starter kit Apr 7, 2017
@weinand
Copy link
Contributor

weinand commented Apr 9, 2017

I've added experimental support for MERN launching: if MERN starter kit is detected a corresponding launch config is generated (if none exist).

@weinand weinand modified the milestones: April 2017, March 2017 Apr 9, 2017
@weinand weinand added feature-request Request for new features or functionality and removed verified Verification succeeded bug Issue identified by VS Code Team member as probable bug labels Apr 9, 2017
@weinand
Copy link
Contributor

weinand commented Apr 10, 2017

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.

@mjbvz mjbvz added the verification-needed Verification of issue is requested label Apr 26, 2017
@chrmarti chrmarti added the verified Verification succeeded label Apr 27, 2017
@chrmarti
Copy link
Contributor

--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...).

@chrmarti chrmarti reopened this Apr 27, 2017
@chrmarti chrmarti added verification-found Issue verification failed and removed verified Verification succeeded labels Apr 27, 2017
@chrmarti
Copy link
Contributor

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

@weinand
Copy link
Contributor

weinand commented Apr 28, 2017

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

@chrmarti chrmarti added the verified Verification succeeded label Apr 28, 2017
@weinand
Copy link
Contributor

weinand commented May 9, 2017

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

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

7 participants