Webpack is throwing an error due to the Vue component type being labeled as "any"

When using ts 4.2.4 and Vue3, I encountered a strange error while building my vue project:

> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a2a7aeaaededb3a2a0a083f3edf2edf3">[email protected]</a> build
> vue-cli-service build


⠋  Building for production...

 ERROR  Failed to compile with 1 error                                                                                                                                                                                  17:36:51

 error  in src/layout/Main.vue:52:20

TS7016: Could not find a declaration file for module './Footer.vue'. '/Users/ddruganov/VSCodeProjects/admin.pacc/src/layout/Footer.vue.js' implicitly has an 'any' type.
    50 | <script lang="ts">
    51 | import Topbar from "./Topbar.vue";
  > 52 | import Footer from "./Footer.vue";
       |                    ^^^^^^^^^^^^^^
    53 | import Sidebar from "./Sidebar.vue";
    54 |
    55 | import { activityStore, LOAD_ACTIVITIES } from "@/store/modules/activity.store";

 ERROR  Build failed with errors.
npm ERR! code 1
npm ERR! path /Users/ddruganov/VSCodeProjects/admin.pacc
npm ERR! command failed
npm ERR! command sh -c vue-cli-service build

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/ddruganov/.npm/_logs/2021-05-08T14_36_51_736Z-debug.log

Typescript is raising an issue regarding the type of Footer being considered as any, but does not show similar complaints about other .vue components.
Interestingly, VSCode does not flag this as an error:
No squigglies are present for Footer
Here is the code for Footer:

<template>
  <footer class="footer bg-light border-top p-3">
    <span class="text-muted">{{ fullYear }} pAcc</span>
  </footer>
</template>

<script land="ts">
import { Vue } from "vue-class-component";

export default class FooterComponent extends Vue {
  get fullYear() {
    return new Date().getFullYear();
  }
}
</script>

The contents of my shims-vue.d.ts file are as follows:

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

Answer №1

custom-vue-definitions.d.ts

declare module '*.vue' {
  import { VueComponentOptions } from 'vue'
  const vueComponent: VueComponentOptions
  export default vueComponent
}

Answer №2

After a keen observation by @tony19, an error in my code was discovered:

It appears there is a mistake in Footer.vue (land=ts should be lang=ts). Is this simply a typo in the question?

The correct syntax should be lang="ts", problem resolved, and the project now compiles successfully.

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

PHP dropdown menu - Retrieve data from second database and display it

Currently, I am working on a project that involves both Vue.js 3 and Laravel 9. In this project, there are two database tables - Employee and Company. The company table consists of only an ID and the company name. On the other hand, the Employee table inc ...

How come this straightforward VueJS component template is appearing in the wrong location in the DOM, positioned above a table?

These illustrative examples are not the actual faulty code, but rather simplified for discussion purposes. Issue with Code The code snippet below displays a table, but unexpectedly places the Component values above the table element visually and in the D ...

Is there a clever method to transform the property names of child objects into an array of strings?

I have a similar object that looks like this: { "name":"sdfsd", "id":1, "groups":[ { "name":"name1", "id":1, "subGroups":[..] }, { "name":"name2", "id":21, ...

Receiving contextual information from Microsoft Teams within an Angular application integrated as a tab

I am currently integrating an Angular website into a Microsoft Teams tab. In order to perform certain computations, I need to retrieve the Team ID. To achieve this, I have recently added npm install --save @microsoft/teams-js. Below is the code snippet th ...

`Unresponsiveness in updating bound property after change in Angular2 child property`

Having trouble with my custom directive and ngOnChanges() not firing when changing a child property of the input. my.component.ts import {Component} from 'angular2/core'; import {MyDirective} from './my.directive'; @Component({ d ...

exit out of React Dialog using a button

I have a scenario where I want to automatically open a dialog when the screen is visited, so I set the default state to true. To close the dialog, I created a custom button that, when clicked, should change the state to false. However, the dialog does no ...

Tips for transferring request variables/data from a middleware to another function in typescript

I need to authenticate a user's jwt token using middleware. This is the middleware I have: const authorized = (req: Request, res: Response, next: NextFunction) => { const token = req.header("token") if(!token){ return res.send("N ...

Intermittent issue with Angular 2 encountered while following the Hero Editor tutorial on angular.io

I am encountering an occasional error in the console while following the angular.io tutorial using Mozilla Firefox. The error does not seem to impact the functionality or rendering of my application, and it only happens sporadically. If you could provide ...

The process of ensuring an element is ready for interaction in Selenium with Javascript

I am currently working on creating an automated test for a Single Page Application built with VueJs. When I click on the registration button, a form is loaded onto the page with various elements. However, since the elements are loaded dynamically, they are ...

How do I navigate to a different page in Vue.js HTML based on user selection?

Here is my first attempt at writing HTML code: <div class="col-md-4" > <div class="form-group label-floating"> <label class="control-label">Select No</label> <select class="form-control" v-model="or" required=""> ...

When I upload a file using v-file-input, it displays two names

While working with nuxt, I made an interesting discovery. See the pattern here The top name is the file that was uploaded, and the bottom one is the target file name. I plan to remove the bottom name and replace it with the top. This is what I envision: E ...

Designing a customized element by deriving from an existing Vue component

I am working on a Vue 2 with Bootstrap project and have multiple buttons that look like this: <b-button variant="outline-secondary" title="..." v.b.tooltip.hover.bottom> <font-awesome-icon icon="..." /> </b- ...

Angular CLI - exploring the depths of parent-child component communication

My issue revolves around accessing the 'edit' method of a child component using @ViewChild, but for some reason it's not functioning as expected. Where could I possibly be going wrong? Here are the console logs: Key parts of the CompanyCom ...

Access exclusive content by subscribing now!

How can I return a reference to a subject from a service without allowing the receiver to call .next() on the subject? Let's say there is a service with a subject that triggers new events. class ExampleService { private exampleSubject = new Subjec ...

I am unable to employ filtering in TypeScript

Hey there, I'm trying to filter some JSON data randomly by using this function, but I keep running into an error with my variable called filteredArray. The error message says "Property 'filter' does not exist on type 'Dispatch<SetSta ...

Displaying messages in an Angular 2 chatbox from the bottom to the top

As a newcomer to using typescript, I am currently working on an angular 2 project and facing some challenges with creating a chatbox. My goal is to have new messages displayed at the bottom while pushing the old ones up one line at a time, as shown in this ...

The Vue.js auto-suggest input feature is causing the HTML layout to have excess whitespace

There seems to be an issue with the auto suggest feature causing extra spaces in the HTML, which in turn pushes down elements like H1, H2, and paragraphs when typing in the suggestion box. App.vue <template> <div id="app"> <Autoc ...

Encountering difficulties in JavaScript while trying to instantiate Vue Router

After following the guide, I reached the point where creating a Vue instance was necessary (which seemed to work). However, it also required providing a Vue Router instance into the Vue constructor, as shown below. const router = new VueRouter({ routes }) ...

Utilizing TypeScript Variables within a Jquery Each Iteration

I have a variable named tableIndexNumber that I need to use in different methods. When trying to access this variable, I use "this.tableIndexNumber" and it works fine. However, I face an issue when using it inside a jQuery each loop because the HTML elemen ...

Execute the Webpack-Dev-Server during the .NET Core compilation process

For the past few days, I've been struggling to make my .NET CORE app run my Vue.js application on the webpack-dev-server during Debug mode. Visual Studio seems to complicate this simple task unnecessarily. My attempt to add a Post-Build event like th ...