Debugger settings for Chrome in VS Code with Vue.js - vue.js

With the following settings in .vscode\launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
I can set a breakpoint in index.js file in my project and it triggers successfully, but the breakpoints in *.vue files triggers incorrectly.
With the following settings:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "vuejs: chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
}
]
}
vice versa, the breakpoints in *.vue files are triggered successfully, but I cannot set a breakpoint in my index.js file.
How to make the breakpoints work in both *.js and *.vue?
See more detailed information on how I set up the environment.

I was very surprised, but adding two versions of the source map override worked for me. I can now set and have it stop on breakpoints in .vue files, .js files, and my imported es6 modules. It only took me about a month to find a solution!
Hope it works for you (this doesn't work for me anymore. See below)
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*",
"webpack:///src/*": "${webRoot}/*"
}
Updated October 2019:
Debugging both js and vue files had broken for me in a recent update. I have finally found new settings that work for both:
"sourceMapPathOverrides": {
"webpack:///src/*.vue": "${webRoot}/*.vue",
"webpack:///./src/*.js": "${webRoot}/*.js"
}

And here is what is working for me in September of 2020 in vsCode 1.49.1: very similar to Steve's answer above:
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/src/*",
"webpack:///./src/*.js": "${webRoot}/src/*.js",
}

Related

How to set breakpoints on js files when working with vue / vite / VSCode / Chrome?

I have various issues with breakpoints using Vue, Vite and VS Code.
I have read other questions/answers, including this one and this one, but have met with no success.
I can set breakpoints in .vue files easily. But with .js files in the same project I can't set a bp until after I have stepped into that file from a .vue file.
What's worse, after I have made a code change I cannot set a bp in a .js file at all, even after stepping into it, until I stop and restart the Vite server.
All the above is with the Chrome browser. Firefox debugging works, up to a point. The problem is that it's impossible to see the contents of objects , I just get
Proxy {<target>: Object, <handler>: Object}
when hovering over an object variable, whereas in Chrome I get to expand down into the object members.
My launch.json settings below; I haven't been able to find the pathmappings equivalent for Chrome.
{
"version": "0.2.0",
"configurations": [
{
"type": "firefox",
"request": "launch",
"name": "Launch FireFox localhost",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}",
"pathMappings": [
{
"url": "http://localhost:5173/src/dragdrop.js",
"path": "${workspaceFolder}/DragDrop/src/dragdrop.js"
}
]
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}/DragDrop",
}
]
}
and this is vite.config.js; I have tried the commented-out parts without success.
import { defineConfig } from 'vite'
import vue from '#vitejs/plugin-vue'
export default defineConfig({
plugins: [vue() ],
// build: {
// sourcemap: true,
// },
root: "DragDrop",
resolve: {
alias: {
vue: 'vue/dist/vue.esm-bundler.js',
// '#': fileURLToPath(new URL('./src', import.meta.url)),
}
}
})

How to configure launch.json in Visual Studio Code to debug VueJS Project with Chrome and put bound breakpoints?

I'm currently working in a symfony/VueJS project. I would like to debug the VueJs part with VSCode and Chrome. When I put a breakpoint on a line of vuejs code after launching the chrome debuging VSCode says the breakpoint is unbound. My VueJS code path is in assets/js.
I configured the .vscode/launch.json as follows and try many configurations, but I got "unbound breakoints" after launching the chrome debuging :
{
"name": "WSL Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8003/login",
"webRoot": "${workspaceFolder}",
"sourceMap": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
},
Have you some ideas ?
Regards
Lamiel
Try the following configuration in your launch.json file
{
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*",
"webpack:///src/*": "${webRoot}/*",
}
}
]
}
Also add the the following vue.config.js file to the root directory of the project
module.exports = {
configureWebpack: {
devtool: 'source-map'
}
}

Visual Studio Code: Breakpoint set but not yet bound - Vue.js

I have a large Vue.js project which I am trying to get Debugging working properly with in VS Code. I've been trying various different things for a full week now and I keep getting problems with binding breakpoints. For what it's worth, these typically crop up worse in classes that are created through a factory pattern or things like Vuex actions that don't have directly accessible function endpoints - this may be related.
Here's a sample of some launch configs...
{
"name": "Parity - Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080/app",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*",
"/./*": "${webRoot}/*",
"/src/*": "${webRoot}/*",
"/*": "*",
"/./~/*": "${webRoot}/node_modules/*"
}
},
{
"name": "Parity - Edge",
"type": "edge",
"request": "launch",
"url": "http://localhost:8080/app",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*",
"/./*": "${webRoot}/*",
"/src/*": "${webRoot}/*",
"/*": "*",
"/./~/*": "${webRoot}/node_modules/*"
}
},
I get exactly the same behaviour in Chrome and in Edge (not surprising as they are essentially the same browser these days).
Upon digging through the Sources tab in the browser I found that the source maps are mostly all within the webpack folders for this, hence why they aren't being found (the exception being the *.vue files, hence why they would work fine).
The following configuration works for me, but the full answer is...
look at where the files are found in 'Sources' in your web browser and
use those locations to map back to the actual file location - doing
what I did before and just trying to use someone else's random config
isn't always going to work.
{
"name": "Parity - Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080/app",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*",
"webpack:///./src/*": "${webRoot}/*",
"webpack:///./node_modules/*": "${webRoot}/node_modules/*"
}
},
{
"name": "Parity - Edge",
"type": "edge",
"request": "launch",
"url": "http://localhost:8080/app",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*",
"webpack:///./src/*": "${webRoot}/*",
"webpack:///./node_modules/*": "${webRoot}/node_modules/*"
}
},

Configuration for Debugging Mocha Unit Tests in Vue.js with VSCode

I am currently facing some problems getting my tests to debug properly with VSCode in Vue.js (I am using Mocha and Webpack)
The first configuration I found which got me a bit closer was this one.
Configuration in .vscode/launch.json
{
"type": "node",
"request": "launch",
"name": "Unit Tests",
"program": "${workspaceFolder}/node_modules/#vue/cli-service/bin/vue-cli-service.js",
"args": [
"test:unit"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
Now this solution did attach but the problem is it was only debuggin inside of the vue-cli-service.js (node_modules/#vue/cli-service/bin/vue-cli-service.js). I tries alot around here but did not came alot closer. So I thought I'd just write a Configuration myself as Vue is just using Webpack and Mocha and this should be possible. Now I got closer but still not to a version that is actually usable. Right now this is the configuration that I have
Configuration in .vscode/launch.json
{
"name": "Run mocha-webpack",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha-webpack/bin/mocha-webpack",
"args": [
"--debug-brk", "5858",
"--timeout", "120000",
"--require", "node_modules/#vue/cli-plugin-unit-mocha/setup.js",
"--webpack-config", "node_modules/#vue/cli-service/webpack.config.js",
"tests"
],
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceRoot}/node_modules/*",
"webpack:///./*": "${workspaceRoot}/*",
"webpack:///*": "*"
},
"stopOnEntry": false,
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
],
"env": { "NODE_ENV": "test"},
"console": "integratedTerminal",
"outFiles": []
}
Now this got me one step closer. I can now at least set a debugger statement in my code and the debugger will stop there. However it will still not react to Breakpoints I have set using VSCode. I guess this must have to do something with the compilation of the code and the sourceMapping but I am so far unable to make this work.
Alright so TLDR
vue.config.js
module.exports = {
"transpileDependencies": [
"vuetify"
],
chainWebpack: config => {
if (process.env.NODE_ENV === 'test') {
config.merge({
devtool: 'cheap-module-eval-source-map',
});
}
}
}
launch.json
{
"type": "node",
"request": "launch",
"name": "Run Unit Tests",
"program": "${workspaceFolder}/node_modules/#vue/cli-service/bin/vue-cli-service.js",
"args": ["test:unit", "--inspect-brk", "--watch", "--timeout", "999999"],
"port": 9229
}
What you want to do is to chain the webpack config so that if you are in testing you change your devtool to one that does not transpile your code like "cheap-module-eval-source".
Thanks to rustyx for pointing that out on GitHub.
Configure webpack to conditional behaviour depending on the environment. This is described in the documentation Working with Webpack and Modes and Environment Variables
of Vue CLI.
For the test-mode, which is used by vue-cli-service test:unit, mutate the devtool to not transpile the code e.g. cheap-module-eval-source or eval-source-map.
vue.config.js
module.exports = {
configureWebpack: config => {
if ((process.env.NODE_ENV === 'development') || (process.env.NODE_ENV === 'production')) {
config.devtool = 'source-map'
}
else if (process.env.NODE_ENV === 'test') {
config.devtool = 'cheap-module-eval-source-map'
}
}
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
},
{
"type": "node",
"request": "launch",
"name": "test:unit debug",
"program": "${workspaceFolder}/node_modules/#vue/cli-service/bin/vue-cli-service.js",
"args": ["test:unit", "--inspect-brk", "--timeout", "900000"],
"port": 9229
}
]
}

How to configure Mocha with VS Code

Hi I'm trying to setup Mocka and Chai frameworks with Visual Studio Code but I'm getting error when I'm trying to run mocha unit test saying:
Attribute 'program' does not exist ('C:\Users...node_modules/mocha/bin/_mocha')
http://prikachi.com/images/321/9672321w.png
It must be something from the settings.
This is the JSON config file of VS Code launch.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": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"bdd",
"--timeout",
"999999",
"--colors",
"${file}"
],
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}