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:

https://i.sstatic.net/lOocZ.png

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:

https://i.sstatic.net/vo1rV.png

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

Encountering the issue: "Unable to establish validator property on string 'control'"

Has anyone encountered this error message before? TypeError: Cannot create property 'validator' on string 'control'" import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core'; import { CommonModule } from &ap ...

Maintain Symbolic Links in Angular Libraries

Hey there! I'm facing an issue with creating an Angular 8 Library using ng-cli. I'm struggling to maintain symlinks when linking my external application with npm link. I attempted to modify my angular.json file like this: "build": { "bui ...

TypeScript types for d3 version 4

I am currently working on a d3 project and to simplify the development process and reduce errors, I decided to implement TypeScript. Using d3 v4, I initially faced issues with incorrect type definitions which led to errors like d3 not having a definition ...

A recursive approach to filling empty space on a canvas using Javascript

My goal was to develop a recursive function that would continue filling the empty spaces of a canvas until reaching the edges or encountering a different colored space. function createFillingPoint() { let x = points[0][0], y = points[0][1]; var pat ...

Encountered an issue while attempting to install the react-twitter-embed package

I've been facing some challenges while attempting to incorporate react-twitter-embed into my react application. Despite trying various troubleshooting steps like deleting and reinstalling the node_modules folder, as well as clearing the npm cache, the ...

Nuxt Axios not connecting with proxy leading to CORS issues

Encountering the following CORS error: Access to XMLHttpRequest at 'https://gw.bilinfo.net/listingapi/api/export' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass acce ...

The file or directory specified does not exist: 'app/src/main/AndroidManifest.xml'

When running the react-native program using code react-native run-android and npm start, I encountered an error regarding the AndroidManifest file. Error ENOENT: no such file or directory, open 'app/src/main/AndroidManifest.xml' package.json ...

Instructions on adding a file path to the package.json file

Is it possible to create a script in the package.json file that allows me to run a file located in the parent folder of the package.json file, rather than the same directory? I would like the syntax to be similar to this: "scripts": { "server": " ...

Deploying an Azure Blob Trigger in TypeScript does not initiate the trigger

After successfully testing my Azure function locally, I deployed it only to find that it fails to trigger when a file is uploaded to the video-temp container. { "bindings": [ { "name": "myBlob", "type&qu ...

Adding a dynamic click event in HTML using IONIC 4

I've created a function using Regex to detect URL links and replace them with a span tag. The replacement process is working fine, but I'm facing an issue where when I include (click)="myFunction()" in the span, it doesn't recognize the cli ...

Tips on streamlining two similar TypeScript interfaces with distinct key names

Presented here are two different formats for the same interface: a JSON format with keys separated by low dash, and a JavaScript camelCase format: JSON format: interface MyJsonInterface { key_one: string; key_two: number; } interface MyInterface { ...

Checking for String Const Type in TypeScript

In my code, I have a custom type called Admin with two possible values: 'ADMIN' or 'AGENT'. There is a function that retrieves the user role from local storage: return localStorage.getItem('role'); I am looking to verify if ...

Exploring different preact.js configurations to set up a simple environment for debugging the source code

Exploring the depths of preact.js has proven to be quite a challenge. Despite successfully setting up the framework using webpack build from the preact-boilerplate setup, I am encountering difficulty in accessing and intercepting the code for debugging pur ...

Ways to remove a

After creating an npm link within a local dependency and then deleting that dependency from my hard drive, I am now attempting to remove this npm link. I have attempted the following steps: npm rm --global dependency npm uninstall dependency npm unlink - ...

Deploying local NPM modules with npm link to Heroku servers

While using npm link to incorporate my local modules into my app, I encountered an issue. It works perfectly on my machine, but after running grunt and deploying it to Heroku, the system claims that my module cannot be found! Currently, all my files are c ...

Having trouble with hanging and failing npm installation on Windows 10?

I keep encountering issues with my npm installations on Windows 10, even though I have the latest stable versions of node.js and npm. Every time I try to run 'npm install' in my project folder, which was initially set up with express following th ...

Having some issues with validating numbers in typescript

When implementing react hook form in my React app, I encountered an issue while validating specific fields and had to add some conditions to the schema. yup .object({ test1: yup.number().when('test2', (test2: number, schema: yup.NumberSchem ...

The Vuetify toolbar with a fixed header functionality

How can I make my v-toolbar stay sticky even when I scroll down? Here is the code snippet I am working with: <div id="app"> <v-app> <v-toolbar dense> <v-toolbar-side-icon></v-toolbar-side-icon> <v-toolbar-ti ...

The file isn't located in 'rootDir', even though all the details seem to be accurate

I'm currently troubleshooting an issue with one package in my nx monorepo that is causing the error code "TS6059". Interestingly, all other packages are functioning correctly in previous builds. After reviewing my index.ts files, it appears that all ...

Encountering the net::ERR_CONNECTION_REFUSED error while working on a project that involves using Laravel 9,

I've been working on developing an app using Laravel 9 and ReactJS with Vite JS. When I tried the following command to build, I encountered some errors. npm run dev The errors I'm facing are as follows: GET http://[::1]:5173/resources/css/ap ...