Tl;dr
The VS Code debugger always saysUnbound breakpoint
but setting break points in chrome dev tools works and opens the respected file in VS Code automatically (after that the VS Code debugger for that file works). Also source (map) files in chrome have weird names likeHelloWorld.vue?4a7c
.
I set up a new VueJS 3 project with Typescript using vue create my_project
. I selected Typescript, Babel and as Vue version 3.
I'm trying to get the VS Code debugger up and running to debug my project the way I used to with other projects like Java. Therefore I copied the best practices from the VS Code recipe sides. (Since there is no VueJS Typescript debugging recipe I used the one for VueJS and Typescript and tried to mix them)
The actual problem is, when I set a breakpoint in VS Code it says Unbound breakpoint
. My assumption is that VS Code can't map any of the source map files to my source files indicating that webpack somehow messes up the file naming or my configuration for file mapping is wrong.
What I got working so far is that when I inspect the project with chrome developer tools I see e.g. a main.ts
where I can set breakpoints and once the breakpoint is hit the file opens in VS Code and the debugger (at least for this specific file) works as expected. When it comes to the .vue
files things are a bit more messed up. In chrome the .vue
files are obfuscated/compiled but there are files named the following way [file-name].vue?[4-digit-hex-value]
(e.g. HelloWorld.vue?4a7c
) which contains the actual source and setting break points in there works and the file will be opened in VS Code automatically.
If anybody could provide a configuration that works in their setup that would help me a lot.
So far I have the following config files:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "vuejs: chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"pathMapping": {
"/_karma_webpack_": "${workspaceFolder}"
},
"sourceMapPathOverrides": {
"webpack:/*": "${webRoot}/*",
"/./*": "${webRoot}/*",
"/src/*": "${webRoot}/*",
"/*": "*",
"/./~/*": "${webRoot}/node_modules/*"
},
"preLaunchTask": "serve"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "serve",
"type": "npm",
"script": "serve",
"isBackground": true,
"problemMatcher": [{
"base": "$tsc-watch",
"background": {
"activeOnStart": true,
"beginsPattern": "Starting development server",
"endsPattern": "Compiled successfully"
}
}],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
(npm serve
just executes the in package.json
defined script "serve": "vue-cli-service serve"
)
tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"moduleResolution": "node",
"experimentalDecorators": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": true,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
vue.config.js
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
configureWebpack: {
devtool: 'source-map',
}
})