The Typescript compiler is unable to locate the module `./app` or its associated type declarations, resulting in error code ts(

When working in VSCode, Typescript is highlighting an error in the file src/main.ts. However, when I run the project, it executes without any errors or warnings.

https://i.sstatic.net/pybuM.png

The configuration in my tsconfig file is as follows:

{
    "compilerOptions": {
        "outDir": "dist",
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node",
        "strict": true,
        "jsx": "preserve",
        "sourceMap": true,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "lib": ["esnext", "dom"],
        "baseUrl": "src",
        "allowJs": true,
        "paths": {
            "@/*": ["./*"],
            "~/*": ["./*"]
        },
        "suppressImplicitAnyIndexErrors": true
    },
    "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
    "exclude": ["node_modules", "dist"]
}

I have a file named App.vue located at src/App.vue with the following content:

<template>
    <div>
        <!-- <h1 v-if="showModal">HELLO WORLDDNIOAS</h1> -->
        <!-- <SignInModal :show-modal="showModal" /> -->
        <HomePage />
        <!-- <router-view></router-view> -->
    </div>
</template>

<script lang="ts">
import { defineComponent, computed, ref } from "vue";
import HomePage from "@/components/HomePage.vue";
import SignInModal from "@/components/SignInModal.vue";
import Test from "@/components/Test.vue";
import { useStore } from "vuex";

export default defineComponent({
    name: "App",
    components: {
        HomePage,
        SignInModal,
        Test,
    },
    setup() {
        const store = useStore();
        const hello = ref(false);
        return {
            showModal: computed<boolean>(
                () => store.getters["modal/showModal"]
            ),
            hello,
        };
    },
});
</script>

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
}
</style>

In addition, I have included type definitions in the file shims-vue.d.ts as shown below:

import Vue, { DefineComponent } from "vue";
declare module "*.vue" {
    //eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
    const component: DefineComponent<{}, {}, any>;
    export { component, Vue };
}

Despite everything running smoothly and displaying correctly, why is VSCode indicating that there is an error?

Answer №1

Vue 3 no longer includes an exported Vue object, instead the correct module declaration is as follows:

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

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

Get the excel file from the assets using vue.js

I need some help figuring out how to download an excel file from my vue.js project. I tried the following code: <template> <div class="row mt-5"> <a href="./assets/template.xlsx" target="_blank">Downloa ...

The Facebook Debugger fails to collect meta-tags from Nuxt pages

I'm currently utilizing Nuxt (Universal) in conjunction with Wordpress through Apollo and Graphql. Here's how I am fetching my content: async asyncData({ app, params, store, route, redirect }) { await store.dispatch("actionSetPageContent ...

Error TS2540: Cannot update the style property as it is designated as read-only

I ran into an issue while working on my TSX markup. The TS typechecker in Vim is giving me the error message 2540: Cannot assign to style because it is a read-only property when I try to create a textarea element. It's odd that textarea.style is read- ...

Using Traefik for HTTPS redirection with Docker Compose, the Vue+Nginx application is encountering a 404

Hello everyone, I am a newbie developer and excited to share that I am deploying my first full stack project. I'm currently working on running a vuejs+nginx client app in a docker-compose setup which includes mysql, a nodejs backend, and traefik for ...

TypeScript React Object.assign method return type

I have a unique custom function that utilizes Object.assign to return a specific result. The documentation mentions that this function returns an array, but surprisingly, it can be destructured both as an array and an object. Check out the code snippet be ...

Typescript tutorial: Implementing a 'lambda function call' for external method

The Issue Just recently diving into Typescript, I discovered that lambda functions are utilized to adjust the value of this. However, I find myself stuck on how to pass my view model's this into a function that calls another method that hasn't b ...

Inheriting static attributes in Typescript without using the static keyword

My project involves utilizing multiple classes that represent entities from a database. abstract class Entity { static columns: Column[]; static showInNav: boolean; static dependencies: string[]; // non-static fields } class Entity_A exten ...

Redux, React, and Typescript work together seamlessly to create a dynamic application that utilizes the Connect function to

I am currently facing an issue with the following code example: import * as React from "react"; import { connect } from 'react-redux'; interface IMessage { message : string; } class SayMessage extends React.Component<IMessage, {}>{ ...

Configuring NextJs routes with multiple parameters

Seeking guidance on structuring files in Nextjs for handling multiple URL parameters. Can anyone offer advice? The given URL structure is: /api/upload?file=${filename}&fileType=${fileType} This is the current file structure: app api upload ...

An operation designed for the specific items within a selection

How can I utilize a function that generates an array of objects as items for vuetify select? This is how I am currently using it: <v-select :items='functionToCall()' ...... > After calling the function and checking the console ...

Using TypeScript to access native functions in react-native

Recently, I found myself in need of a basic function to interact with native code. Rather than creating a package, I opted to create the Java files as if they were for a plugin and registered them in MainApplication. As I'm using TypeScript, I am cur ...

Upgrade your project from Angular 5 to Angular 9 using webpack

I want to share my experience, not ask a question! To upgrade dependencies in package.json: -Update all Angular dependencies to version 9 -Add these dependencies: "@angular-devkit/build-angular": "^0.900.4", "@angular-builders/cu ...

Is there a way to determine the return type without using a type variable?

I am striving to develop a function that can clone an array while maintaining the original data types. The current issue I am facing is that TypeScript is declaring the return type as any: export function cloneArray(inputArray) { return [...inputArray ...

Nuxt-Gmap displaying multiple infowindows

Does anyone know how to close an info window if a user clicks on another marker? In the Google documentation, you open infowindows manually, but in nuxt-gmap it's like this: <GMap :key="mapRender" ref= ...

What is the process for importing a Vue component into Vue and dynamically replacing a value within it?

Seeking guidance with VueJs as a new user. I'm looking to have a template loaded on every product page, where the ID of the product is dynamically substituted into the template. In my child Vue component, I am importing template.vue: <template> ...

What is the process of importing JSON data into the store using Nuxt.js?

I am attempting to retrieve a JSON file without the need for a server. After reading this article on Vuex store being undefined in NUXT middleware, I incorporated it as middleware. The JSON file failed to load without any error displayed. The issue remai ...

steps to authenticate with dynamic database information instead of hard-coded data

After following a tutorial, I successfully created my first register login system in dot net and angular. The issue I encountered is that the author used static data in the tutorial's code example. However, I want to implement my own database data. As ...

Warning: Please note that the command 'vue init webpack my-project' is deprecated and may not be supported in future

My Objective: I aim to start a Vue.js project by executing the command vue init webpack myproject Expected Outcome: The installation of all dependencies without any fatal errors, and being able to run the project using npm dev run, accessible at http://lo ...

"Rollup, Typescript, and ESLint: a trifecta of warning

I developed a project with Rollup that incorporates Typescript and ESLint along with the typescript-eslint plugin. I've noticed that ESLint is running on compiled code instead of the original source. Below is my Rollup configuration : export default ...

Verify if an entity (either an object or a class) possesses a specific attribute

Imagine having a class like this: module MyModule { export class MyClass { x:number; y:number; } } Now, let's say we have a string called "x". How can we determine if MyClass has the property "x"? If an instance of MyClass is ...