Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Enable debugging in Chrome and VS Code - fixes #435 #436

Merged
merged 1 commit into from
Sep 19, 2018
Merged

Enable debugging in Chrome and VS Code - fixes #435 #436

merged 1 commit into from
Sep 19, 2018

Conversation

nsivertsen
Copy link
Contributor

@nsivertsen nsivertsen commented Sep 12, 2018

This PR makes it possible to start and connect to a debugging session inside the dev server of a Sapper app from Chrome and VS Code. Previously this only worked from ndb.

See #435

Chrome:

  1. $ cd my_sapper_project
  2. $ node --inspect node_modules/sapper/dist/cli.js dev
  3. visit chrome://inspect in Chrome
  4. click on "Open dedicated DevTools for Node"
  5. (you might have to add the folder of your Sapper project to the workspace)

VS Code:

  1. Debug > Add Configuration...
  2. Use the following launch.json:
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "dev",
      "program": "${workspaceFolder}/node_modules/sapper/dist/cli.js",
      "args": [
        "dev"
      ],
      "autoAttachChildProcesses": true
    }
  ]
}
  1. Debug > Start Debugging

I've found the experience of coding in VS Code with a dev server + debug session running in the background quite pleasurable: Make some changes, hit save, the app is rebuilt, all while your breakpoints and watch expressions stay in place.

I've tried this in Webstorm, and it works there as well, until you change a file and hit save. Webstorm tries to hold onto the previous server process (which has been killed) and gets confused when you try to carry on stepping through your code. I assume this is a bug in Webstorm, and not a Sapper problem.

Fixes #435

@@ -57,6 +59,7 @@ class Watcher extends EventEmitter {
'dev-port': dev_port,
live,
hot,
'devtools-port': devtools_port,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this here with an eye towards making the DevTools port a command-line switch in the future.

@Rich-Harris
Copy link
Member

Oh wow, this is awesome! Thank you

@quantuminformation
Copy link

quantuminformation commented Aug 14, 2019

@nsivertsen can you share your exact settings and steps to debug this in webstorm please?

I tried
Screenshot 2019-08-14 at 12 30 43

Do you debug the generated server folder file or the src?

@nsivertsen
Copy link
Contributor Author

Hi @quantuminformation, I unfortunately don't current have access to the computer I tried this on with Webstorm, but your config seems right, apart from the working directory (I would set that one level higher up), and you need to pass the dev flag to cli.js. I would turn on source maps and debug the source.

@quantuminformation
Copy link

Great, that seems to have worked now, will play around.

Screenshot 2019-08-15 at 10 45 53

@quantuminformation
Copy link

For posterity: ndb is https://github.com/GoogleChromeLabs/ndb

@quantuminformation
Copy link

quantuminformation commented Aug 19, 2019

I made a video to show this debugging in action:

https://www.youtube.com/watch?v=x155wGkbKm8

Any ideas on how to debug a sapper app running on cloud run?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Debugging Sapper app server in dev mode in Chrome or VS Code not possible
3 participants