My dev team configured a Node.js project with TypeScript to use Vite as dev server, using the npm script panel of VsCode. Is there a way to attach the debugger into this Vite server so we can debug the TSX code within the editor?
VS Code's built-in debugger helps accelerate your edit, compile and debug loop. VS Code has built-in debugging support for the Node.js runtime and can debug JavaScript, TypeScript, or any other language that gets transpiled to JavaScript.
Remote debugging. VS Code does not itself support remote debugging: this is a feature of the debug extension you are using, and you should consult the extension's page in the Marketplace for support and details. There is, however, one exception: the Node.js debugger included in VS Code supports remote debugging.
VS Code keeps debugging configuration information in a launch.json file located in a .vscode folder in your workspace (project root folder) or in your user settings or workspace settings. To create a launch.json file, open your project folder in VS Code ( File > Open Folder) and then select the Configure gear icon on the Run view top bar.
For debugging other languages and runtimes (including PHP, Ruby, Go, C#, Python, C++, Powershell and many others), look for Debuggers extensions in our VS Code Marketplace or select Install Additional Debuggers in the top-level Debug menu. Below are several popular extensions which include debugging support:
The previous answer is for debugging in Chrome, if you prefer Firefox, here's the debug.json.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "firefox",
"request": "launch",
"name": "vuejs: firefox",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
}
]
}
Very important: the "webRoot": "${workspaceFolder}/src",
needs to point the the directory where your 'Vue.app' file is located. If that doesn't work, put the directory where your 'index.html' file is located. One of these two should work.
Further info can be found in this discussion on the official Vite GitHub repo: https://github.com/vitejs/vite/discussions/4065
Go to the debug tab and click "create debug.json".
Then adapt the url port to use 4000 if you want to use the Vite plugin for VSCode. Or 3000 if you run it with yarn dev
, npm run dev
or vite
from your console.
I also had to adapt the webRoot as I've created an app folder which is my root folder.
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4000",
"webRoot": "${workspaceFolder}/app"
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With