Building modules (lib) with Vite + Vue3 + Typescript fails
See original GitHub issueDescribe the bug
Building a module with Vite fails when the final product is built (vite build
). But it works in developer preview (vite
).
Reproduction
- Create a Vue3+TS module as described in https://vitejs.dev/guide/build.html#library-mode
- Build for distribution with
npm run build
- Use it in another Vite+Vue3+TS project
Sample project: sample.zip
How to use:
- Go into
/lib
and call:npm install && npm run build
- Go into
/main
and call:npm install && npm run build && npm run serve
Expected: See output from lib
component.
Actual: No output, but console output from same component shows up. Also works in dev mode, try npm run dev
.
System Info
vite
version: 2.0.5- Operating System: macOS M1 11.2.3
- Node version: v15.11.0 (brew)
- Package manager (npm/yarn/pnpm) and version: 7.6.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Vue 3 + Vite + Typescript - dev & build not picking up TS Errors
I'm using Vue 3, Vite and TypeScript. I wanted to give a try of building Vue project with TypeScript. The configuration has been...
Read more >Building a Vue3 Typescript Environment with Vite - miyauci.me
Vite is a build tool developed by Evan You, the author of Vue. It uses native ES Module imports to provide a fast...
Read more >Build a typescript component library with Vite - Ivancic Josip
Vite is a fast new build tool that is intended for modern web projects. It uses native ES modules and provides a blazing-fast...
Read more >Building for Production - Vite
By default, Vite targets browsers which support the native ES Modules, ... is time to bundle your library for distribution, use the build.lib...
Read more >cannot find module 'vite' or its corresponding type declarations
Can you check if it works if you change your Index.spec.ts to a .js file? The error you're getting is because TypeScript doesn't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In general it would be great to have an example of best practice how to use vite to build modules / libs ❤️
It looks like the issue origins from duplicate integration of
vue
package. Using https://vitejs.dev/config/#resolve-dedupe seems to solve the issue. Invue.config.ts
add:This was hard to find. Adding an example to the documentation or the scaffolding code would be very much appreciated.