question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Building modules (lib) with Vite + Vue3 + Typescript fails

See original GitHub issue

Describe the bug

Building a module with Vite fails when the final product is built (vite build). But it works in developer preview (vite).

Reproduction

  1. Create a Vue3+TS module as described in https://vitejs.dev/guide/build.html#library-mode
  2. Build for distribution with npm run build
  3. Use it in another Vite+Vue3+TS project

Sample project: sample.zip

How to use:

  1. Go into /lib and call: npm install && npm run build
  2. 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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

8reactions
holtwickcommented, Mar 9, 2021

In general it would be great to have an example of best practice how to use vite to build modules / libs ❤️

4reactions
holtwickcommented, Mar 14, 2021

It looks like the issue origins from duplicate integration of vue package. Using https://vitejs.dev/config/#resolve-dedupe seems to solve the issue. In vue.config.ts add:

  resolve: {
    dedupe: ["vue"],
  },

This was hard to find. Adding an example to the documentation or the scaffolding code would be very much appreciated.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found