Dividing component files using TypeScript

Our team has embarked on a new project using Vue 3 for the front end.

We have opted to incorporate TypeScript and are interested in implementing a file-separation approach. While researching, we came across this article in the documentation which provides an example. Unfortunately, the example does not demonstrate how to achieve this with TypeScript.

We attempted the following structure:

/components
┗ /SideBarBtn
  ┣ sidebar-btn.scss
  ┣ sidebar-btn.ts
  ┗ sidebar-btn.vue
 

sidebar-btn.vue

<template>
    <h1 class="test">This is a test</h1>
</template>
<script lang="ts" src="./sidebar-btn.ts"></script>
<style lang="scss" src="./sidebar-btn.scss"></style>

sidebar-btn.scss

.test {
    color: blue;
}

sidebar-btn.ts

import { defineComponent } from "vue";

export default defineComponent({
  name: "SideBarBtn",
});

Home.vue

<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png" />
    <SideBarBtn />
  </div>
</template>

The command npm run serve runs without errors and the page loads successfully. However, the component remains invisible and a warning message appears in the console stating "Component is missing template or render function."

How can we resolve this issue?

Answer №1

The issue stemmed from the <script> section within the Home.vue file. The SideBarBtn component was not functioning properly due to how it was imported using an alias method @/...

Home.vue

<script lang="ts">
import { defineComponent } from "vue";
import SideBarBtn from "../components/SideBarBtn/sidebar-btn.vue"; // Ensure that the complete name of the vue file is used, including the .vue extension

export default defineComponent({
  name: "Home",
  components: {
    SideBarBtn
  }
});
</script>

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

How can you trigger a page method from a layout event in Vue.js?

I'm working on a design that includes a sidebar and an image gallery on the page. Initially, all images are loaded without any filters applied. However, when a button in the sidebar is clicked, I want the page to display filtered images. Although I ca ...

Understanding how to handle prop types in a React application using Typescript

My current task involves using the react-google-maps library to integrate Google Maps API into my project. The documentation specifies a certain way to set up the maps component: const GoogleMapComponent: React.ComponentClass<{}> = compose( with ...

What is preventing this composable from being reactive?

In my application, I have implemented this composable: // src/composition-api/usePermissions.js import { ref, readonly } from 'vue' import { fetchData } from 'src/utils/functions/APIFunctions' export function usePermissions() { const ...

Updating $data within a VueJS directiveIs there something else you

We have a component and a directive. The structure of our component data is as follows: { langs: [ { title: '', content: '' }, { title: '', content: ...

The import of type cannot be done within paths in tsconfig

Currently, I am tackling a server side project utilizing TypeScript. In this context, I have established various types in ooo.d.ts and configured the paths within tsconfig.json. However, upon attempting to import the specified type, an error is being displ ...

What is the most conventional method for documenting the types within a Vuex state declaration?

Within one of our components, we are dealing with a substantial state that looks like this in the code: export default { someObject: {}, someOtherObject: {}, evenMore: [] <etc...> } It's difficult to understand what's happening wi ...

RouterModule is a crucial external component that is essential for integrating

If I have a very simple component that is part of an Angular component library, it might look like this: mycomponent.module.html <div> <a routerLink="/"> </div> mycomponent.component.ts import { Component, OnInit, Input } from &a ...

Experiencing a 404 error after attempting to access an endpoint following a successful MSAL Azure AD

Incorporating the UserAgentApplication.loginPopup function to authenticate users on our Azure AD has been a challenge as we transition from an ASP.NET MVC application to a Vue.js front end and ASP.NET 'API' backend. The goal is to pass the access ...

Explanation of Default Export in TypeScript

I recently started learning about JS, TS, and node.js. While exploring https://github.com/santiq/bulletproof-nodejs, I came across a section of code that is a bit confusing to me. I'm hoping someone can help explain a part of the code. In this project ...

Error: The import declaration is clashing with the local declaration of 'defineProps' in Vue version 3.3

Today, I encountered several errors after updating my node_modules and Vue to v3.3. The project utilizes Vue 3.3, WebPack (not Vite), and VS Code Volar. It is a large project. In every file with *.vue containing <script setup lang="ts">, ...

Utilizing TypeScript 3.1: Easier Array Indexing with Enums in Strict Mode

Enabling TypeScript "strict" mode with "noImplicitAny" causes this code to fail compilation. I am looking for guidance on how to properly declare and use Arrays indexed by Enum values. namespace CommandLineParser { enum States { sNoWhere, sSwitchValu ...

Issue with displaying Typescript sourcemaps on Android device in Ionic 2

Encountering a strange behavior with Ionic2. After deploying my app to a simulator, I am able to view the .ts file sourceMap in the Chrome inspect debugger. In both scenarios, I use: ionic run android However, when deploying my APK on a real device, th ...

Maintaining database consistency for multiple clients making simultaneous requests in Postgres with Typeorm and Express

My backend app is being built using Express, Typescript, Typeorm, and Postgres. Let's consider a table named Restaurant with columns: restaurant_id order (Integer) quota (Integer) The aim is to set an upper limit on the number of orders a restaura ...

Resource is used to return an array as an object

There is something peculiar going on. I have come across an array structured like this: => [ "optionalinformation" => [ "domain" => [ "type" => "string", ], ], ] This particular array is utilized by a reso ...

Methods for adding a new object to an array in Angular: Explained

How can I insert a new object in Angular? Here is the current data: data = [ { title: 'Book1' }, { title: 'Book2' }, { title: 'Book3' }, { title: 'Book4' } ] I would like to update the obje ...

What is the process for extracting the "path expression" from an interface in TypeScript?

My goal is to achieve the following structure: type Post = { id: number title: string author: { name: string } comments: { text: string }[] } type ExtractPathExpressions<T> = ??? type Paths = ExtractPathExpressions<Post> / ...

getting specific article by id -- vue routing, vuex

Trying to retrieve the article ID and navigate to the detail page for that specific ID. Attempted the following code snippet but encountered an error in the console: api/v1/article[object%20Object]:1 Failed to load resource: the server responded with ...

Installing the Quasar UI framework into an existing Vue JS project can be done with just a few

I am currently working on a Vue JS project and I am looking to incorporate some components, such as range sliders. However, I am struggling to understand how to integrate these components into my existing project. I have tried following tutorials for insta ...

The underscore convention for defining members in Typescript allows for clear and concise

Let's talk about a class called Email class Email { private _from: string; private _to: Array<string>; private _subject: string; } When an email object is created, it will look something like this: { _from:'', _to:'&apo ...

Having Trouble with Typescript Modules? Module Not Found Error Arising Due to Source Location Mismatch?

I have recently developed and released a Typescript package, serving as an SDK for my API. This was a new endeavor for me, and I heavily relied on third-party tools to assist in this process. However, upon installation from NPM, the package does not functi ...