I am facing an issue with TypeScript where it is unable to locate the Vue3 module or its associated type declarations,

Hey there, I'm currently stuck on this error and unable to figure out how to solve it. Both files are located in the same directory: ...assets\article-area\

[tsl] ERROR in C:\www\office\assets\article-area\index.ts(2,18)
      TS2307: Cannot find module './Test.vue' or its corresponding type declarations.
ts-loader-default_e3b0c44298fc1c14
 @ ./assets/index.ts 12:14-45

This is my index.ts

import {createApp} from "vue";
import Test from "./Test.vue";

export default () => {
    document.querySelectorAll(".article-edit-area-select").forEach((root: HTMLElement) => {
        let app= createApp(Test);
        app.mount(root);
    });
}

And here's my Test.vue

<template>
Test
</template>

<script lang="ts">

export default {
  name: "Test",

}
</script>

I have a feeling that this error might be due to incorrect settings in my tsconfig.json. Could it be possible?

Here's my tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true,
    "lib": [
      "dom",
      "es5",
      "es2015.promise",
      "es2015.collection"
    ]
  },
  "exclude": [
    "node_modules"
  ],
  "include": [
    "assets/**/*.ts"
  ]
}

As for my Webpack.config...

...
  module: {
        rules: [
            {
                test: /\.ts$/,
                loader: "ts-loader",
                exclude: /node_modules/,
                options: { appendTsSuffixTo: [/\.vue$/] },
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.(styl|stylus)$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    // 'style-loader',
                    'css-loader',
                    'postcss-loader',
                    'stylus-loader'
                ]
            },
            {
                test: /\.(css)$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    // 'style-loader',
                    'css-loader',
                    'postcss-loader'
                ]
            },
            {
                test: /\.(png|jpg|gif|svg|ttf|woff|woff2)$/,
                type: "asset/resource"
            }
        ]
    },
...

The interesting thing is, despite the error output during 'npm run watch', the code still compiles and works fine in the browser. Quite perplexing, isn't it? :/

Answer №1

To implement this, consider adding the code snippet below to a shims-vue.d.ts file:

declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const customComponent: DefineComponent<{}, {}, any>
  export default customComponent
}

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

Broadcasting events across the entire system

I'm trying to accomplish something specific in Angular2 - emitting a custom event globally and having multiple components listen to it, not just following the parent-child pattern. Within my event source component, I have: export class EventSourceCo ...

Access the Apollo cache to retrieve a query that is not currently in existence, but contains all the necessary information already stored in the cache

At my graphql endpoint, I have a query that can be input as follows: fragment ChildParts { id __typename } fragment ParentParts { __typename id children { edges{ node { ...ChildParts } } } query { parents { ...

Why is the render not showing up on the screen when combining Vue 3 with VTK.js?

While going through the specified VTK.js/Vue.js tutorial with a newer 3.x version, why is it that the cone doesn't appear on the browser window? ...

Dealing with useEffect being invoked twice within strictMode for processes that should only execute once

React's useEffect function is being called twice in strict mode, causing issues that need to be addressed. Specifically, how can we ensure that certain effects are only run once? This dilemma has arisen in a next.js environment, where it is essential ...

What is the best way to mock a Typescript interface or type definition?

In my current project, I am working with Typescript on an AngularJS 1.X application. I make use of various Javascript libraries for different functionalities. While unit testing my code, I am interested in stubbing some dependencies using the Typings (inte ...

"Transforming a Java byte array into a ReactJS video: Step-by-step guide

I am getting a file from a Java API server and need to convert it into a video using React JS. The Java API server converts the video file into a byte array using Files.readAllBytes(file) and I need to use this video file byte array to create a video fil ...

Add an input element to a form fieldset by employing vue

In my form, I have a staged approach with 3 fieldsets that only appear when the "Next" button is clicked. Now, in the third fieldset, I need to add input elements based on keys extracted from an external json object. Data: data: () => ({ c ...

Compare the values of properties in an array with those in a separate array to filter in Angular/TypeScript

There are two arrays at my disposal. //1st array tasks.push({ ID: 1, Address: "---", Latitude: 312313, Longitude: 21312 }); tasks.push({ ID: 3, Address: "---", Latitude: 312313, Longitude: 21312 }); //2nd array agentTasks.push({ID:2,AgentID: 2,TaskID:1}); ...

Data not reflecting changes in component when field is modified?

I currently have a table on my web page that displays data fetched from an array of objects. The data is collected dynamically through websockets by listening to three different events. User can add an entry - ✅ works perfectly User can modify ...

Execute TypeScript via command line

After installing ts-global and setting the default ts config, I encountered an issue while trying to compile my file with custom configurations. The command tsc worked fine, but when I tried adding a file path like tsc myfile.ts, nothing seemed to work. F ...

Guide to correctly importing a class definition from a module in TypeScript

Having trouble integrating the AsyncAPI Generator into my typescript project. The generator, being a commonjs module, is causing some complications. import { Generator } from '@asyncapi/generator'; const generator = new Generator('@asyncapi ...

Special vue directive that displays content only if it exists

Often, I find myself needing to display a div (or another element) only if it contains content. This requires duplicating the reference to the content in the tag and in v-if, as shown below... <div v-if="store.sometimesIWillBeEmpty">{{store.sometime ...

Using bootstrap-vue: incorporating tailored css styles

Looking to incorporate a tooltip from bootstrap-vue, but experiencing layout changes when adding the following CSS imports: import 'bootstrap/dist/css/bootstrap.css' import 'bootstrap-vue/dist/bootstrap-vue.css' Is there a way to impor ...

VS Code failing to detect Angular, inundated with errors despite successful compilation

Having some issues with loading my angular project in vscode. It used to work fine, but suddenly I'm getting errors throughout the project. I have all the necessary extensions and Angular installed. https://i.stack.imgur.com/qQqso.png Tried troubles ...

Ways to retrieve the quantity of a particular value within an object using TypeScript

I'm inquiring about how to retrieve the number of a specific value within an object using TypeScript. Here is the structure of the object: obj : TestObject = { name: "test", street: "test" subobj1: { status: warning, time: ...

Creating xml sitemap for dynamic URLs in a Nuxt application

I am in the process of adding sitemaps to a website that has multiple storefronts. To generate a /sitemap/sitemap.xml file for static pages such as the homepage, terms and conditions, and privacy policy, I have utilized the nuxt sitemap module. In additi ...

Could you tell me the kind of theme used in Material-UI version 5?

I've decided to switch my project over to MUI version 5 and embrace the use of emotion CSS. It's come to my attention that I need to incorporate the theme property, but now TypeScript is prompting me for a type definition for it. The current code ...

The component variable fails to update after choosing an option from the select tag

Is there a way to dynamically populate a second select tag based on the selected option from the first select tag in VueJS? I am facing an issue where the variable declared in the component does not update even though the API response is correct when a cho ...

If the condition is not met, Vue directive will skip rendering the element

I've decided to create my own system for managing roles and rights in Vue since the existing options are not meeting my needs. Currently, I am able to hide an element when a user lacks the necessary role, but what I really want is to completely preve ...

Ensure that the click event on the HTML element is only triggered one time

In my application, I have the following code snippet. The issue is that this code resides in each table column header. Therefore, whenever I click on a mat-select option, new values are generated and used in an *ngFor loop for mat-option. The problem aris ...