Appendix
Breakpoint Debugging
Edit this page on GitHubIn addition to the @debug
tag, you can also debug Svelte and SvelteKit projects using breakpoints within various tools and development environments. This includes both frontend and backend code.
The following guides assume your JavaScript runtime environment is Node.js.
Visual Studio Codepermalink
With the built-in debug terminal, you can set up breakpoints in source files within VSCode.
- Open the command palette:
CMD/Ctrl
+Shift
+P
. - Find and launch "Debug: JavaScript Debug Terminal".
- Start your project using the debug terminal. For example:
npm run dev
. - Set some breakpoints in your client or server-side source code.
- Trigger the breakpoint.
Launch via debug panepermalink
You may alternatively set up a .vscode/launch.json
in your project. To set one up automatically:
- Go to the "Run and Debug" pane.
- In the "Run" select menu, choose "Node.js...".
- Select the "run script" that corresponds to your project, such as "Run script: dev".
- Press the "Start debugging" play button, or hit
F5
to begin breakpoint debugging.
Here's an example launch.json
:
ts
{"version": "0.2.0","configurations": [{"command": "npm run dev","name": "Run development server","request": "launch","type": "node-terminal"}]}
Further reading: https://code.visualstudio.com/docs/editor/debugging.
Other Editorspermalink
If you use a different editor, these community guides might be useful for you:
Google Chrome and Microsoft Edge Developer Toolspermalink
It's possible to debug Node.js applications using a browser-based debugger.
Note this only works with debugging client-side SvelteKit source maps.
- Run the
--inspect
flag when starting the Vite server with Node.js. For instance:NODE_OPTIONS="--inspect" npm run dev
- Open your site in a new tab. Typically at
localhost:5173
. - Open your browser's dev tools, and click on the "Open dedicated DevTools for Node.js" icon near the top-left. It should display the Node.js logo.
- Set up breakpoints and debug your application.
You may alternatively open the debugger devtools by navigating to chrome://inspect
in Google Chrome, or edge://inspect
in Microsoft Edge.