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: https://i.sstatic.net/uCY3W.png
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

When working with Angular/Typescript, the error message "compilation of 'export const' is not possible

Embarking on creating my very own Angular library, I took the first step by adding a service without any issues. The challenge arose when I decided to move a constant to a file named tokens.ts for the service to reference. Following this change, the build ...

Determine the data type of the value for the mapped type

Is there a way to access the value of a type like the following: interface ParsedQs { [key: string]: undefined | string | string[] | ParsedQs | ParsedQs[] } I am looking for a method to retrieve the ParsedQsValue type without directly duplicating it from ...

Methods for adjusting data based on the current user's login

I'm currently working on integrating a user login feature using Angular 6 for a stock management system. The user credentials are saved in the database, and I have successfully retrieved them into a component (login) for validation. After a successful ...

"Upon studying the Reflect-metadata index.d.ts file, I find myself perplexed by the variances in

While utilizing the reflect-metadata package, I encountered this particular type. However, I am uncertain about its meaning and function signature. function metadata(metadataKey: any, metadataValue: any): { (target: Function): void; ( ...

What steps should I take to resolve the issue of 'unable to locate the name 'OktaAuthService' error?

I am currently trying to incorporate authentication into an Angular application using Okta. I have carefully followed the step-by-step instructions provided in the documentation at this link: . However, I am encountering an error when attempting to start t ...

Error: The function setIsEnabled does not exist

Currently, I am in the process of merging two separate next.js projects to create a website that can utilize the Cardano wallet 'Nami'. The code for accessing the wallet functions correctly in its original project, but when transferred over, it p ...

Errors can occur when using TypeScript recursive types

Below is a simplified version of the code causing the problem: type Head<T> = T extends [infer U,...unknown[]] ? U : never; type Tail<T> = T extends [unknown,...infer U] ? U : []; type Converter = null; type Convert<T, U extends Converter& ...

Incorporate a background image into mat-dialog

I've been struggling to set a background image on my mat-dialog, but for some reason it's not showing up at all. I attempted using a panelClass as well, but still no luck. .custom-panel .mat-dialog-container { background-image: url("../. ...

Navigating the process of passing data in a VueJS 2 application

As a newcomer to VueJS 2, I'm seeking feedback on my current approach. My system involves uploading files containing data that is used to generate charts. As such, I display the uploaded files for users. <tr v-for="file in files.data" :key="file.i ...

To enable iteration of iterators when trying to spread, utilize the TypeScript compiler option '--downlevelIteration'

I have a function that accepts an argument of either an object or an array. const handleScenarioChange = (scenario: Scenario | Scenario[]) => { if (isArray(scenario)) { const scenarios = [...state.selectedScenarios, ...scenario]; const unique ...

Can content projection be utilized from a child component in Angular?

Keep in mind, this example could be achieved without using content projection. I am just showing a simplified version here. Imagine having a component that displays lists of names in two separate elements: import { Component } from '@angular/core&ap ...

Following the deployment on Heroku, changes made to Vue.js components and the app.scss file in the Laravel application are not reflected

My Laravel/Vue.js application runs smoothly on localhost, but I encountered issues after deploying it to Heroku. Styles added to app.scss are not compiling into my public/css file, resulting in no visible effect. Additionally, modifications made to my Vue. ...

What could be the reason for `process.env.myvariable` not functioning in a Next.js project with TypeScript

After creating a file called .env.local in the root directory of my project, I added a variable called WEBSOCKET_VARIABLE=THIS_IS_TEXT to it. However, when I try to access it using process.env.WEBSOCKET_VARIABLE, nothing is found. What could be causing ...

Transform the `PascalCase` format into `strictCamelCase` in TypeScript type conversion

By utilizing the built-in Uncapitalize<S> function, you can easily convert a string like FooBar to fooBar: const fooBar: Uncapitalize<'FooBar'> = 'fooBar'; However, this method proves inadequate when dealing with class name ...

The routes in Laravel and Vue.js seem to exist, but the DELETE and PUT methods return a 404 not found error

For some reason, I am encountering a "404 not found" error when attempting to perform PUT or DELETE requests, even though the route exists and everything was previously functioning correctly... My project is built on Laravel and Vue.js. All GET requests ...

What is the best way to ensure type safety in a Promise using Typescript?

It seems that Promises in Typescript can be type-unsafe. This simple example demonstrates that the resolve function accepts undefined, while Promise.then infers the argument to be non-undefined: function f() { return new Promise<number>((resolve) ...

Leveraging enums within strictFunctionTypes for Typescript generics

Here is a code snippet (TS playground link): const enum Enum { A, B, C } interface Args { e: Enum.A; } interface GenericClass<A> { new (args: A) : void; } class TestClass { constructor(args: Args) {} } function func<A>(C: GenericCl ...

When attempting to pass props to children, Typescript triggers an error message

I am facing an issue with a component that renders a child based on the specific "league" a user is viewing, such as MLB. Typescript is throwing an error because I am not passing the correct props to the child component. However, the parent component has t ...

The iframe came to a halt as soon as it was no

I am currently developing a live video website that utilizes third-party tools to play the videos. To simplify things, I have embedded all the components required for live video into a single HTML page. Here is how it looks: <iframe data-v-140cfad2= ...

Creating a Vue single file component in conjunction with Laravel 5.5

Concern: [Vue warn]: Unknown custom element: - did you correctly register the component? For recursive components, ensure the "name" option is provided. Test.vue: <template> <p>test</p> </template> <script> //al ...