Distributing a library of components using Vite, Vue 3, and Typescript to npm

My current challenge involves publishing a Vue 3 component library with Vite, all written in Typescript. The issue I'm facing is that the type definitions are not being included in the package when imported into another project.

Upon importing the component, the following error message shows up:

Try `npm i --save-dev @types/repo__mypackagename` if it exists or add a new declaration (.d.ts) file containing `declare module '@repo/mypackagename';

I understand that a declaration file is needed, but how can this be achieved specifically with Vite & Vue 3?

Key sections of my package.json:

{
  ...
  "files": [
    "dist"
  ],
  "main": "./dist/celestia-vue.umd.js",
  "module": "./dist/celestia-vue.es.js",
  "exports": {
    ".": {
      "import": "./dist/celestia-vue.es.js",
      "require": "./dist/celestia-vue.umd.js"
    }
  },
  "unpkg": "./dist/celestia-vue.umd.js",
  "jsdelivr": "./dist/celestia-vue.umd.js",
  "scripts": {
    "vite:dev": "vite",
    "serve": "vue-cli-service serve",
    "vite:serve": "vite preview",
    "build": "vue-cli-service build",
    "vite:build": "vue-tsc --noEmit && vite build",
    "test:unit": "vue-cli-service test:unit",
    "lint": "vue-cli-service lint"
  },
  ...
}

The tsconfig.json configuration:

{
  "compilerOptions": {
    ...
  },
  ...
}

In addition to the vite.config.ts code:

import { defineConfig } from 'vite'

import vue from '@vitejs/plugin-vue'
import typescript from '@rollup/plugin-typescript';

...

export default defineConfig({
  plugins: [
    ...
  ],
  resolve: {
    alias: {
      ...
    },
  },
  build: {
    lib: {
      ...
    },
    rollupOptions: {
      ...
    }
  }
})

The build output lands in the dist folder here:

I suspect there might be a simple oversight either in the vite.config.ts file or elsewhere in my setup.

For context, here is how my Vue 3 component library is structured:

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

A step-by-step guide on implementing easydatatable in Vue.js with the help of Axios

I am fetching this information using axios { "qtp1459016715-18382027": { "name": "qtp1459016715-18382027", "status": "5", "priority": 5, "thread-id": 18382027, &quo ...

Error encountered while running React Native on an iOS device

When attempting to run React Native code on my iPhone, I encountered the following error message. The code runs smoothly on Android and Expo, but it fails to execute on a physical device. I would greatly appreciate any assistance provided. E:\reac ...

Is a compiler necessary when using npm for imports?

I was wondering about something, I recently installed jquery locally via npm and crafted the following HTML code: <body> <script> import jquery from "jquery"; </script> </body> Unfortunately, I encountered an error. My brows ...

How to calculate the sum of all values in a FormArray in Angular

I am trying to retrieve the input values from each row and then calculate the sum of these rows. Here is my HTML code: <ng-container formArrayName="cap_values"> <tbody *ngFor="let item of capValues.controls; let i=index" [formGroupName]="i"& ...

Neglect variables that have not been declared (TypeScript)

Currently, I am working on developing a WebExtension using TypeScript that will be later compiled into JavaScript. This extension relies on one of the browser APIs offered by Firefox, specifically the extension API. An example of this is my use of the get ...

Leverage the power of v-model props in your Vue 3 component to efficiently retrieve API breakpoints

I am currently working on integrating the API breakpoints in my child component. These components are designed for my football web application. The breakpoints are sourced from: api-football My challenge lies in passing multiple prop values into a c ...

The issue with Angular2 Material select dropdown is that it remains open even after being toggled

Exploring the world of Node.js, I am delving into utilizing the dropdown feature from Angular Material. However, an issue arises once the dropdown is opened - it cannot be closed by simply clicking another region of the page. Additionally, the dropdown lis ...

Can a standalone Angular plugin be developed for seamless integration within different Angular websites?

My affinity for Angular runs deep. That being said, I have a desire to develop an Angular plugin that can be seamlessly integrated into websites using various frameworks. Whether it's Angular or something different, my goal is compatibility across th ...

Encountering difficulty generating CSS using TailwindCSS

Despite numerous attempts to set up the autoprefixer, I keep encountering this error >npx tailwindcss@latest build ./src/styles.css -o ./dist/styles.css npx: installed 80 in 5.546s Cannot find module 'autoprefixer' Require stack: - C:\Use ...

Using Vue Test Utils to simulate window scrolling

Looking for guidance on testing a window scroll event using vue-test-utils. Here is the Javascript code: export default { created () { window.addEventListener('scroll', this.topBResize); }, methods: { topBResize () { var he ...

I attempted to unsubscribe from an observable in Angular, but I encountered an error stating that the unsubscribe function does not exist

Here is the code snippet from a components.ts file in an Angular project. I encountered the following error during compilation: ERROR merge/merge.component.ts:75:12 - error TS2551: Property 'unsubscribe' does not exist on type 'Observable& ...

Tips for utilizing npm version to increase the numerical value preceding the prepatch/preid suffix

Seeking guidance on utilizing npm version with prepatch (and other pre- options) / preid to properly increase the count after the suffix. For example: I currently have v.0.5.22 and wish to add -rc I executed npm version prepatch --preid rc This results i ...

Incorporate the {{ }} syntax to implement the Function

Can a function, such as toLocaleLowerCase(), be used inside {{ }}? If not, is there an alternative method for achieving this? <div *ngFor="let item of elements| keyvalue :originalOrder" class="row mt-3"> <label class=" ...

I am encountering a challenge when trying to invoke a different function within the Facebook login callback in my

In my Vue2 application, I have implemented a login system using Facebook login. This system captures the access token from the Facebook API and sends it to the backend for processing user data. When the user clicks on the "login with Facebook" button, the ...

Having trouble fetching information from a JSON file stored in a local directory while using Angular 7

I am currently experiencing an issue with my code. It works fine when fetching data from a URL, but when I try to read from a local JSON file located in the assets folder, it returns an error. searchData() { const url: any = 'https://jsonplaceholde ...

While using the ionic serve command

Every time I attempt to execute Ionic, an error is triggered. Your assistance is greatly appreciated. Interestingly, the AppData file has been erased as well! 'ionic' is giving me this message: "not recognized as an internal or external command ...

Covering Vue methods with Jest and Coverage: a comprehensive guide

My goal was to improve the code coverage percentage by covering specific if statements within Vue methods. I am using package versions @vue/test-utils:"^1.1.4" and vue: "^2.6.12". Below is a snippet of my component: <template> <div :class=& ...

Please enter the password to install jest using yarn add command

While attempting to install yarn add jest in the work repository I cloned onto my machine, I encountered an error. C:\COMPANY_NAME\Work-Folder\frontend>yarn add jest yarn add v1.13.0 [1/4] Resolving packages... [2/4] Fetching packages.. ...

creating and managing multiple redirect routes in vue.js application

const router = new VueRouter({ routes: [ {path: '*', redirect: '/'} } )} I have configured this as the default redirect route in my routes.js file. Now, I am wondering how I can set multiple redirect paths and trigger them ...

A guide to integrating a component into another component in Angular

Currently, I am encountering an issue with importing a component into another in my Ionic 5.0.0 application. Within my application, I have two separate modules: ChatPageModule and HomePageModule. My objective is to include the Chat template within the Hom ...