The sourcemap for a Vue file based on TypeScript is not available due to the presence of the lang="ts" attribute

I am facing an issue where I need to transition my vue files from JavaScript to TypeScript.

Currently, they have a standard structure like this:

<template>
...
</template>

<script>
...
</script>

To use them with TypeScript, I learned that I should change the script tag to <script lang="ts">. This modification works smoothly, and the code is successfully built/transpiled via webpack, allowing me to launch my app. However, I encountered a problem when I added lang="ts" to the script tag – Chrome no longer displays these files in debug mode, indicating a lack of sourcemap information for them (although I am not very familiar with sourcemaps). So, my question is how to ensure the correct generation of sourcemaps and display the files in Chrome developer mode again, as debugging will be necessary. Sourcemaps are available for all other files and are visible in dev mode on Chrome (e.g., for plain .ts files) and for vue files that are not yet TypeScript-based and therefore do not have the lang="ts" attribute.

Here is an excerpt from my webpack configuration for ts and vue files:

devtool: 'inline-source-map',
module: {
    rules: [
      { test: /\.vue$/,
        loader: 'vue-loader'
      },
      { test: /\.ts$/,
        exclude: /node_modules|vue\/src/,
        loader: "ts-loader",
        options: {
          appendTsSuffixTo: [/\.vue$/]
        }
      }
    ...
    ]
},
resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json', '.ts']
  },

Additionally, here are my tsc settings related to sourcemaps and other potentially relevant configurations:

"sourceMap": true,                  
"strict": true,                         
"alwaysStrict": true,                  
"moduleResolution": "node",          
"allowSyntheticDefaultImports": true,  
"esModuleInterop": true,                   

/* Source Map Options */
// "sourceRoot": ""; 
//"mapRoot": "",
//"inlineSourceMap": true,              
// "inlineSources": true  

Answer №1

After experimenting, I discovered that setting

devtool = 'cheap-module-eval-source'
enabled functionality, albeit with some display issues regarding directory visibility and file endings. Although it technically works, I wouldn't consider it an ideal solution. If anyone knows of a better option, please share. Another challenge I encountered was Sonarqube not supporting lang="ts" due to it being a feature request that has yet to be implemented.

In conclusion, the workaround that proved effective for me involved not using .vue files, but instead utilizing class-based SFC components as outlined in https://v2.vuejs.org/v2/guide/typescript.html#Class-Style-Vue-Components along with a vscode plugin for highlighting inline HTML code. This approach allowed me to have functioning TypeScript, source maps for debugging, Sonarqube compatibility, syntax highlighting, and linting. In my opinion, while vue.js is a powerful framework, there are still significant gaps in the surrounding environment if you venture off the well-trodden path.

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

Is the Vue.js development server automatically increasing the port number when running the yarn serve command?

Every time I start my Vue development server using yarn serve, the port on which my project is served increments by 1 (from 3000 to 3001). I always make sure to exit the previous process before running it again... Do you know why this might be happening? ...

"Utilizing Vue props to manipulate numerical data values in a

I am facing an issue with my raw data when using uuid_short() from the database in Vue props. The number seems to round up or down unexpectedly. What can I do to fix this? For example: In test.blade.php: <div class="content-wrapper"> ...

Specific generic types do not incorporate abstract type context

Take a look at this code snippet: type Data = { person: { id: number; name: string; age: number } item: { id: number; name: string; price: number } transaction: { id: number; personId: number; itemId: number; quantity: number } } type Action<T ex ...

Element not recognized: <my-company-form-extra> - have you properly registered this component?

I've been attempting to render a component using the is directive <template> <div> <v-tabs v-model="currentTab" fixed-tabs> <v-tab v-for="(item, i) in tabItems" :key="i">{{ item }} < ...

Looking for a specific phrase in the data entered by the user

I am dealing with data in ckeditor that looks like this: <p>test 1</p> <p>test 2</p> <p><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICw ...

Exploring the concept of union types and typeguards in TypeScript

I'm struggling with this code snippet: function test(): any[] | string { return [1,2] } let obj: any[] = test(); When I try to run it in vscode, I get the following error message: [ts] Type 'string | any[]' is not assignable to type & ...

Is there a disparity in capabilities or drawbacks between ViewChild and Input/Output in Angular?

As I delve into Angular ViewChild and compare it to Input/Output parameters, I can't help but wonder if ViewChild has any drawbacks or limitations compared to Input/Output. It appears that ViewChild is the preferred method, as all parameters are now ...

The error message "ReferenceError: window is not defined in Angular Universal" indicates

Currently, I'm utilizing Angular 10 and undergoing the process of incorporating SSR into my project. Upon executing the npm run serve:ssr, I encounter the following error: ReferenceError: window is not defined After conducting a search online, the r ...

Having trouble appending a new attribute to the Mongoose output

In my Nodejs server application, I am working with a userDetail document that contains all the relevant user information. Additionally, I have a login document that stores the time of the first login, which I need to incorporate into the userDetails result ...

Nuxt js is throwing an error stating that it is unable to locate the pages directory

I have made changes to the folder structure of my Nuxt.js project. I am encountering an issue: Error - Couldn't find a pages directory in D:\sample. How can I access the pages? .nuxt, app, node_modules, server, .eslintrc, package, package-lock ...

Optimal utilization of JSON in JavaScript API: Enhancing Performance, Reinforcing Maintainability, and Optimizing Resources

Currently, I am working on developing an application using Laravel and VueJS (along with Vuex). Although I do not have much experience in working with these frameworks or front-ends, I am curious to know the best practices for utilizing the data received f ...

Vue shared component interacting with various parent components

I am curious about the best practice for communication between Vue.js common components and different parent components. For instance, in my situation, I have a basic modal component that needs to trigger a 'close' method, but it is being used by ...

Tips for attaching an event listener to a div element that is accessed by reference in a React and TypeScript environment

I am attempting to attach an event listener to the div element using a ref. In my code, I have added a ref called div_ref to the Wrapper div and accessed that div_ref in the enableDragEventListeners method to add event listeners to it on component mount. ...

Utilizing Sequelize to establish associations between tables based on non-primary key columns

Here is the code snippet: User.hasMany(UserMail, {foreignKey:'to_user_id', sourceKey:'id'}); User.hasMany(UserMail, {foreignKey:'from_user_id', sourceKey:'id'}); UserMail.belongsTo(User, {foreignKey: 'from_use ...

The module called "discord.js" does not have a component named "Intents" available for export

Issue with importing module '"discord.js"' - 'Intents' not exported. Here is the code in question: import dotenv from 'dotenv'; const bot = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents. ...

What steps can I take to stop Vetur and TypeScript from displaying duplicate TypeScript warnings in VSCode?

I have a Vue2 project using TypeScript in VSCode with Vetur and TypeScript extensions installed. Whenever there is a TypeScript warning, both the TypeScript and Vetur overlays show duplicate warnings. Example of duplicate warnings Also, the intellisense ...

Navigating Errors within Express Class Using Typescript

I encountered an issue while transforming my Express.js application into a Typescript class, specifically with error handling. Below is the content of my App.ts class file: import express from 'express'; import compression from 'compression& ...

Having difficulty customizing Mui Accordion with Styled Utility implementation

I am having trouble overriding the CSS for an Accordion using Mui styled utility. I am trying to apply a custom CSS class, but there seems to be an underlying class that is causing issues in my code. Here is the Mui class snippet: <div class="MuiPa ...

Making a HTTP Get request for a single item in Ionic 2

I have successfully implemented an API to retrieve data and display it on the page. It works perfectly for a json response containing more than one object, as it follows a "matches" hierarchy. However, I am facing an issue when trying to print out data for ...

What steps can be taken to safeguard data while navigating within the Angular framework?

I am facing an issue with storing an array of items in a service (referred to as cart service) and displaying it in the component (cart.component.ts). The components bgview.component.ts and single.component.ts are involved in selecting individual items, wi ...