-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Debug Server Side code using --inspect #1144
Comments
I know it's normally not very nice to add a comment about +1. But I must emphasize how absolute critical debugging is for the developer experience. @thekip is there something I can help with to help with this? |
Not for me, i just submitted a feature request. Looks like there is no interest from the maintainer's side, so if you implement this and prepare a PR it would be nice for everyone. |
Looks like this would be solved by vitejs/vite#3928 |
I was curious about that and it turns out it's a few clicks in VS Code to make this work. I put together a clickable walkthrough at https://twitter.com/mikenikles/status/1495781582996750337. |
Debugging with "debugger;" statements was always possible, problem with debugging using breakpoints in ide. The main benefit of IDE breakpoints vs "debugger;" statements you don't need to stop and rebuild/reload current file and don't loose a debugging context. |
I'm not sure that there's anything SvelteKit could do here — by the time you've invoked the It's easy to start the dev server with the inspector without editing the run script: NODE_OPTIONS="--inspect" npm run dev Beyond waiting for the Vite PR to get merged is there anything to be done here, or can this issue be closed? |
I get |
No idea why the port is in use; Looks like there's nothing for Kit to do here, so I'll close this |
This may help: I get the same error when adding NODE_OPTIONS from the terminal, but the debugger listens when adding NODE_OPTIONS to the |
The vite PR has been closed without merging - vitejs/vite#3928 |
Is there any current workaround to inspect responses to server-side requests? |
There's another PR (vitejs/vite#9740) that looks like it may solve this, but it hasn't had any responses. |
@Rich-Harris I think what Kit could do here is document how developers should debug server-side code. Even if it’s the same as how to debug Vite-served apps generally, it’s important enough to the developer experience that it deserves a mention in SvelteKit’s docs. I was able to attach the Chrome DevTools debugger by running Vite directly: NODE_OPTIONS=--inspect ./node_modules/.bin/vite dev Running Vite via |
Attaching Chrome DevTools debugger is certainly better than nothing, but could we please agree that SvelteKit most certainly deserves a well-documented best of all frameworks debugging experience? Maybe this issue could be re-opened or a milestone created of some sort. |
+1. Currently evaluating SvelteKit for a new project, but the lack of clear guidance on how to debug client & server is causing me to pump the brakes -- hard. I can't imagine developing a serious app using "printf" debugging (which lots of folks seem to be doing from my searches), and it's quite surprising for such an otherwise progressive framework. |
In case anybody stumbles upon this thread in search of how to debug server side, the following launch.json works perferecly for me:
credit: https://gist.github.com/kiliman/a9d7c874af03369a1d105a92560d89e9 |
@rolanday, The client side Sveltekit debugging is quite good. I've had no issue debugging client side code with Sveltekit in Chrome or Vscode. The basic Chrome web app configuration works well {
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}"
} |
@woahitsraj Thanks, no issues here either re: client-side. The OP was asking specifically about server-side, and above launch.json works well. (I went a little too far to say perfect since no sourcemaps, but it's javascript so not a big deal when compared to needing to printf debug.) There's a recent discord discussion as well, also referencing this ticket, which is what drew my attention back to here. Had it not been for the above launch.json, SvelteKit would have been a non-starter for me, but super glad I found a solution because I'm loving SvelteKit so far!! https://discord.com/channels/457912077277855764/1066511264311951490/1066511264311951490 |
Launching the process using But since my code's in TypeScript + .svelte files, setting JS breakpoints isn't useful. 😢 |
@BMorearty I used to add a debugger statement when I'm debugging in phpstorm/webstorm.. it's not fun. |
@unlocomqx Thank you, that did the trick. By the way I couldn't set breakpoints in VS Code either (not even in .js files) even with @rolanday's launch.json but I didn't mention it because that's not my daily editor. Using |
Hello. I expected the server-side debug is a formality and I'm just disappointed to see it's not the case and this ticket is closed without a clear way to do this. If I launch the configuration with I only get this in the Stack part:
There is another subtility to success for a server-side debugging ? |
There are different configs in circulation for server-side debugging. I use this one for +server.js and +page.server.js. +page.js runs in the browser during dev, and you can debug it there. You need to work with I complement this approach with Thunder Client for API routes. It's a VS Code extension, and you can store your requests in JSON files and commit them. |
Using debugger statements is a weak workaround. We need to push to get actual sourcemap support in Vite for SSR. |
Here's my solution to this problem: cyco130/vavite#17. It uses Node's experimental ESM loader feature, enabling sourcemaps and breakpoints on the server. The downside is, it almost certainly leaks memory. I find it an acceptable compromise since restarting the server once in a while is enough the clean up resources but your mileage may vary. |
Finally, thanks @cyco130, it works for sveltekit |
Amazing, thank you @cyco130 ! After installing vavite as per the Usage instructions in that pull request, I could then debug the server-side typescript code using the following simple VSCode
|
Replacing this
with this
helped me |
just a heads up for future viewers, with vite let plugins = [sveltekit()];
if (mode === 'development') {
const loaderPlugin: Promise<any> = Promise.resolve(nodeLoaderPlugin())
plugins = [loaderPlugin, ...plugins];
}
return {
// ... your code ...
plugins
}; Working with WebStorm I also had to to add But it seems to work now, thanks for your efforts :) |
hmm I'm getting
No matter what I try. Maybe this 'fix' is outdated? |
It would be nice to have an option to enable node debugging for server-side code to be able to stop on breakpoints inspect variables and etc.
Proposed syntaxis is:
Currently, it's possible to start debugger using:
This enables inspecting and i successfully connected to the nodejs using Chrome Dev Tools.
But looks like server-side code generated without source maps and it makes it impossible to put breakpoints inside IDE such as Vs Code or Webstorm (they just ignore breakpoints and execute code without stop).
So when --inspect option is set we should pass through this flag to nodejs and enable sourcemaps in all transpilers/vite
The text was updated successfully, but these errors were encountered: