Tips for troubleshooting a VueJS 3 Typescript project in VS Code and Chrome with SourceMaps (using Vue CLI and Webpack)

TL;DR: The VS Code debugger shows "Unbound breakpoint" error, but setting breakpoints in Chrome DevTools works. Chrome opens the respective file in VS Code automatically (after which the VS Code debugger for that file functions properly). Additionally, source files in Chrome have strange names like "HelloWorld.vue?4a7c."

I recently set up a new VueJS 3 project with Typescript using "vue create my_project". I chose Typescript, Babel, and Vue version 3 during setup.

I'm attempting to get the VS Code debugger running to debug my project similar to how I've done it with other projects, such as Java. I followed the best practices recommended by VS Code documentation. Unfortunately, since there isn't a specific debugging recipe for VueJS Typescript, I combined the VueJS and Typescript recipes and tried to adapt them for my needs.

The issue I'm facing is when I set a breakpoint in VS Code, it displays an "Unbound breakpoint" message. It seems that VS Code is struggling to map any of the source map files to my actual source files. This suggests that webpack may be causing issues with file naming or there could be an error in my file mapping configuration.

So far, I've managed to inspect the project using Chrome Developer Tools and set breakpoints in files like "main.ts," where the debugger works as expected once a breakpoint is hit. However, dealing with ".vue" files is more complex. In Chrome, these ".vue" files are obfuscated/compiled, but they show up as files named in a format like "[file-name].vue?[4-digit-hex-value]" (for example, "HelloWorld.vue?4a7c"). Setting breakpoints in these files works, and the corresponding file opens in VS Code automatically.

If anyone has a successful configuration setup that works in their environment, I would greatly appreciate some guidance.

Currently, I have the following configuration files:

launch.json

...

Answer №1

The approach I've decided to take at the moment is as follows:

(I'm not entirely sure what goes on in the background, but somehow it seems to work - I really don't know if source maps are being generated or not)

I simply utilize the official VS Code Chrome debug setup and included a pre-launch task that initiates the developer server which serves the application in dev mode. Surprisingly, this seems to be all that's required for seamless integration with a fully functional VS Code debugger for my VueJS 3 Typescript application (including Tailwind).

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-chrome",
            "request": "launch",
            "name": "My VueJS Chrome",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}",
            "preLaunchTask": "serve",
            // "userDataDir": "${env:HOME}/.vscode/vscode-chrome-debug-userdatadir" 
            // This config is to always use the same configuration for the chrome app (system wide) 
            // therefore you can install the prefered extensions once and they will stay!
            // Taken from here: https://stackoverflow.com/questions/51725854/run-vscode-chrome-debugger-with-its-extensions
        }
    ]
}

tasks.json (This is the official VueJS VS Code pre launch task recipe)

{
    "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
            }
        }
    ]
}

Simply place these two files into the .vscode directory of your project root and you're good to go!

OFF-TOPIC (Installation of tailwindcss):

Followed the official setup guide from here - adapted to work with vue cli create instead of vite.

1. Install tailwindcss, postcss, autoprefixer - generate tailwindcss config files

Using npm:

npm install -D tailwindcss postcss autoprefixer

Using yarn:

yarn add tailwindcss postcss autoprefixer

Generate the config files:

npx tailwindcss init -p

2. Add these two lines to the tailwind.config.js file:
The important lines are:

    "./index.html",
    "./src/**/*.{vue,js,ts,jsx,tsx}",

So your file should resemble this:

module.exports = {
  content: [
    "./index.html",
    "./src/**/*.{vue,js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

3. Create a ./src/index.css file and include the @tailwind directives for each of Tailwind’s layers.

@tailwind base;
@tailwind components;
@tailwind utilities;

4. Import the recently-created ./src/index.css file in your ./src/main.js file.

import { createApp } from 'vue'
import App from './App.vue'
import './index.css'

createApp(App).mount('#app')

Note the import './index.css'

That's all there is to it. Simply start using it with npm run serve or yarn serve, or follow the setup outlined at the beginning of this solution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with Vuetify's 'text-wrap' class not functioning properly for wrapping text to the next line? Find out

I'm encountering an issue where words get cut off on my cards and are moved to a new line. Here is an image showing the problem: https://i.sstatic.net/9mWbx.png I attempted to resolve this issue by using the class="text-wrap", but it did no ...

Is there a way to simulate a minified module for testing purposes?

For my project, I developed a component intended to function as a module. The implementation involves the utilization of third-party code provided in the form of a config file (initOpinionLab.js) and a .min.js file (opinionlab.min.js). As part of the devel ...

Verifying Vuejs values post-click testing

<!-- custom template --> <div> <textarea v-model="someText">{{someText}}</textarea> <div v-if="hasError">Oops, an error occurred</div> <input v-on:click="store" type="submit" value="update" /> </div ...

Adding a Component in Ionic 3: Step-by-Step Guide

When I run this command: ionic generate component my-component It creates the following folder structure: components my-component my-component.ts my-component.scss my-component.html components.module.ts Now, I want to i ...

Confirming changes to checkbox values in Angular 2 prior to updating

My current challenge involves implementing a confirmation dialog in my application, and I'm feeling a bit unsure about the logic behind it. UserDetailsComponent.ts import { Component, OnInit, OnDestroy, ViewChild, Input, OnChanges, SimpleChange } f ...

The Nuxt loading progress bar keeps appearing and disappearing repeatedly

While the default nuxt loading bar is effective on simple pages, I encountered an issue when making multiple axios requests where the progress bar would load each time a request was sent. I needed the progress bar to recognize all these requests as a singl ...

`Planning the layout of an Angular application with distinct sections`

I've been working on breaking down my Angular app into separate sections and I have a few queries about how to proceed: auth login (only public page in the entire system, after login users are directed to either the admin or user portal based on ...

How can I correctly annotate property 'firebase' on type '{ children?: ReactNode; }' in order to resolve the error?

My firebase object is provided through a higher order component as shown below: const FirebaseContextInterfaceLocal: FirebaseContextInterface = { value: new Firebase() } ReactDOM.render( <Router history={history}> <FirebaseContext.Provi ...

Is it possible to extract TypeScript types from one interface in order to integrate them into another separate interface?

Having a TypeScript interface defined as follows: interface SampleShape { prop1?: string; prop2?: string; } Additionally, I have another separate interface in mind to utilize: interface Payload { model: { name?: string; prop1?: ...

Nested arrays in an Angular interface

As a newcomer to Angular with a background in Java, I am accustomed to setting up classes as data structures for my information. However, after doing some research, I have learned that interfaces should be used instead. I am facing an issue understanding ...

What is the ideal configuration for Typescript within ASP.NET 4 MVC 5 on Visual Studio 2015?

Currently, I am in the process of integrating a TypeScript project into a VS2015 MVC 5 project (which is based on ASP.NET 4, specifically not asp.net 5 or asp.net 6 - only the MVC portion is version 5). All aspects of my query pertain solely to this target ...

React.js: If you encounter this file type, make sure to set up the necessary loader as no loaders are currently set to process it

I encountered an issue while working on my React project with Material Kit React framework. Specifically, I needed to use NavPills from Material Kit React, but when I attempted to run the npm server, I received the following error message: ERROR in ./node_ ...

Struggling to update TypeScript and encountering the error message "Unable to establish the authenticity of host 'github.com (192.30.253.113)'"

While attempting to update my version of TypeScript using npm, I ran into an issue when trying to execute the following command: localhost:Pastebin davea$ npm install typescript/2.8.4 --save-dev The authenticity of host 'github.com (192.30.253.113)&a ...

Traversing fields of a document within a Firestore collection using Angular

Attempts to retrieve the user's photoUrl based on their ID have been unsuccessful. Here is a snapshot of my firestore collection, can someone please guide me on how to access the photoUrl? https://i.stack.imgur.com/p2Zvm.jpg The main collection is &ap ...

What is the role of the 'type' attribute in a button element

I am in need of a customized button that can optionally receive a type attribute: export interface ButtonProps { children: React.ReactNode; onClick?: (e: React.MouseEvent<HTMLElement>) => void; type: ?? } export const Button: React.Functio ...

Preventing style conflicts in react-native with styled-components

Attempting to customize the properties of a button in the calling component using styled-components, but encountering issues. The overriding of properties does not seem to be successful, and the button appears unchanged. The button is defined as follows: ...

Numerous issues persist in Angular 6 related to unresolved errors such as crypto, fs, http, https, net, path, stream, tls, and zlib

Each time I attempt to run my Angular 6 app on localhost, a series of errors pop up that include missing modules like 'crypto'. Though some can be installed, others like 'crypto' are built-in. This is baffling as these folders do not ex ...

Learn how to incorporate a custom event listener for Vuetify's v-select component by utilizing directives

My issue involves a v-select element <v-select :items="[1, 2, 3]" label="Some items" v-mydirective ></v-select> Along with the following directive: Vue.directive("mydirective", { bind: function(el, binding) { ...

basic tiptap add-on or advanced prosemirror module

Exploring the possibilities of utilizing the tiptap editor for Vue.js in conjunction with the Prosemirror editor has sparked my interest. I've delved into a lot of information about tiptap, however, I must admit that the documentation is not as compr ...

Tips for disregarding global CSS in Nuxt.js?

I've been utilizing a boilerplate that integrates with the CoreUI template from GitHub, and it's been working well. However, I am now looking to customize my index page with a unique style, and I'm encountering issues where the global CSS fr ...