Guide on building a Vue3 component with TypeScript, Pug Template engine, and Composition API

Whenever I try to export components within

<script setup lang="ts">
and then use them in
<template lang="pug">
, an error is thrown stating that the component is defined but never used. Here's an example:

<template lang="pug">
div
  // Even when using kebab-case, like hello-world, the same issue occurs
  HelloWorld
</template>
<script setup lang="ts">
import HelloWorld from'@/components/HelloWorld.vue';
</script>

The error message displayed is: Error: 'HelloWorld' is defined but never used

Answer №1

Here is the solution I came up with:

<template lang="pug">
div
  // Make sure to use kebab-case, such as hello-world, to avoid any issues
  HelloWorld
</template>

<script setup lang="ts">
import HelloWorld from'@/components/HelloWorld.vue';
</script>

<script lang="ts">
export default {
  components: {
    HelloWorld,
  }
}
</script>

The key takeaway here is to clearly define our components. As mentioned on Vue.js documentation, we can use multiple script tags if necessary!

I hope you find this information helpful.

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

Implementing unique union type in React: Effective ways to declare typescript type for prop value

I am currently facing an issue where I need to set a specific type for a prop value. However, the challenge lies in the fact that the types are string unions which can vary depending on the usage of the React Component. Let me provide you with the TypeScr ...

server running on node encountered an error due to a port that is already in use

The Server instance emitted an 'error' event at: at emitErrorNT (net.js:1340:8) at processTicksAndRejections (internal/process/task_queues.js:84:21) { code: 'EADDRINUSE', errno: 'EADDRINUSE', syscall: 'listen', addre ...

Having trouble getting Safari to load preflight CORS authentication requests (XHR) in a Vue.js application hosted on Apache?

I've been spending hours researching and trying to debug, but I'm not having any luck. This workflow/request works fine on Chrome, but Safari and Firefox both fail at the OPTIONS preflight request. Safari shows two errors: (!) Failed to load res ...

mongoose memory leak attributed to jest

UPDATED 2020-09-14 I've encountered an issue with a test case I wrote. While the testcase passes, it raises a complaint about improper teardown and an open connection. Can anyone help identify the problem: Approach to Solving the Issue - Memory Leak ...

Encountering an Issue with Vue 3 and Vue Router 4: Uncaught TypeError - Trying to Access Undefined Properties (specifically 'push')

I'm currently working with Vue 3, Vue Router 4, and TypeScript in my project. However, I've encountered an issue while trying to utilize router.push(). Every time I attempt this, I receive a console error stating: Uncaught (in promise) TypeError: ...

Issue with Angular9-MatDatePicker: Unable to establish a connection with 'ngModel' as it is not recognized as a valid attribute of 'input'

Despite my efforts to implement ngmodel binding with matdatepicker, I am still encountering issues, even after reviewing multiple other posts on the topic. Here is a snippet of my HTML: <mat-form-field> <mat-label>Start Date</mat-label ...

Accurate TS declaration for combining fields into one mapping

I have a data structure called AccountDefinition which is structured like this: something: { type: 'client', parameters: { foo: 3 } }, other: { type: 'user', parameters: { bar: 3 } }, ... The TypeScript declaration ...

In vue, pagination links are displayed as dots instead of numbers

Struggling to integrate pagination in vue. Facing an issue where the pagination links are appearing as dots, depicted in the attached image. The correct number of pagination links display and I can navigate through different pages using the side navigation ...

Tips for enforcing strict typing in TypeScript when implementing abstract functions

Consider the following scenario with two classes: abstract class Configuration { abstract setName(name: string); } class MyConfiguration extends Configuration { setName(name) { // set name. } } In this setup, the name parameter in M ...

Enhancing Vue with Vueify and Babel 7

I am currently utilizing a combination of Gulp, Browserify, Vueify, and Babel for my vue.js project development. My hands are tied to using Gulp as the build system and unfortunately, I had to upgrade from Babel 6 to Babel 7 due to the integration of Jest ...

What are the steps to fix the error stating that 'loginError.data' is an unknown type?

Recently delving into typescript, I decided to test the waters with nextjs, rtk query, and antd. However, while attempting to access error within useLoginMutation using the property error.data.message, it was flagged as type unknown. To tackle this issue, ...

Why is TypeScript giving an error about an undefined object key, even though the key was assigned a value in the previous command?

type MaybeThereIsAValue = { [p: string]: string | undefined } ... let bar: MaybeThereIsAValue = {}; const key = "carpe"; bar[key] = "diem"; const why = bar[key]; // why is string | undefined I am confused as to why why is showing ...

Retrieve a particular item using the NGXS selector and incorporate it into the template

I am retrieving stored configuration settings from an API. Each setting includes an 'ID' and several properties like 'numberOfUsers', etc. I am utilizing NGXS for managing the state. My goal is to specifically fetch the 'numberOf ...

Setting up Vue.js API endpoints

I'm a newbie in VueJS, and I recently started using RxJS, Vue rx, and Vue Resource in a mixin to facilitate making HTTP calls and receiving observables anywhere... it's fantastic! Now, I decided to experiment with the following code: subscripti ...

Error: Unable to locate sportsRecord due to missing function

updated answer1: Greetings, I have updated the question with some detailed records and console logs for better understanding. sportsRecord = { playerTigers:[ {TigerNo: 237, TigerName: "Bird Bay Area", TigerkGroupNo: 1, isDefault: true ...

Can a reducer be molded in ngrx without utilizing the createReducer function?

While analyzing an existing codebase, I came across a reducer function called reviewReducer that was created without using the syntax of the createReducer function. The reviewReducer function in the code snippet below behaves like a typical reducer - it t ...

Implement the administration sw-media-quickinfo functionality within the Shopware 6 platform

Is there a way to incorporate administrative action in this https://i.stack.imgur.com/EviNq.png? I am aware that I need to either override or extend the component, but how do I determine the correct one and what should be included in the second override a ...

What is the recommended TypeScript type for setting React children?

My current layout is as follows: export default function Layout(children:any) { return ( <div className={`${styles.FixedBody} bg-gray-200`}> <main className={styles.FixedMain}> <LoginButton /> { children } ...

Having difficulty maintaining trailing zeroes in decimals after converting to float in Angular

I need assistance with converting a string to float in Angular. Whenever I use parseFloat, it seems to remove the zeros from the decimal values. How can I ensure that these zeros are retained with the numerical values? The example below should provide more ...

Encountering a Babel error while attempting to compile my front-end assets using Laravel Mix. The module build process fails, causing

I've been struggling to fix this persistent error, trying various solutions from different sources including Git, but nothing seems to work. Error: Module build failed: this.setDynamic is not a function In my package.json file, I have the following ...