Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
holtwick opened this issue Mar 9, 2021 · 7 comments · Fixed by #11032
Closed

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

holtwick opened this issue Mar 9, 2021 · 7 comments · Fixed by #11032
Labels
documentation Improvements or additions to documentation

Comments

@holtwick
Copy link

holtwick commented Mar 9, 2021

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
@holtwick
Copy link
Author

holtwick commented Mar 9, 2021

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

@holtwick
Copy link
Author

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.

@brunokunace
Copy link

I have a similar issue, i try make a lib with ts, vue3 and vite and all works to publish on npm, but when i try to use this on another project, yarn/npm not found on node_modules this package.

package: https://github.com/brunokunace/vue3-pix

Error:
IMG_20210323_232129_517

anyone can help? Its my first time making a lib.

(accept PR too)

@holtwick
Copy link
Author

@brunokunace You refer to vue- but you generate vue3- named files. The file names do not match. It is a typo you need to fix in package.json.

@Shinigami92 Shinigami92 added p3-minor-bug An edge case that only affects very specific usage (priority) bug has workaround and removed pending triage labels Mar 24, 2021
@brunokunace
Copy link

@holtwick yes, is it, sorry about this stupid question, now all works!

@patak-dev patak-dev added documentation Improvements or additions to documentation and removed bug has workaround p3-minor-bug An edge case that only affects very specific usage (priority) labels Jul 21, 2021
@jscptman
Copy link

i reproduced the bug, and the process didn't even report an error.😳

@igortrinidad
Copy link

I'm facing the same issue while updating a Vue library:

https://github.com/igortrinidad/vue-number-format/blob/update-docs-vue-installation/vite.config.js

The library build runs successful, the application run successfully with the library in development mode but when the application build throws this error:
2022-09-19 08_51_15-package json - vue-number-format  WSL_ Ubuntu  - Visual Studio Code

sodatea added a commit to sodatea/vite that referenced this issue Nov 22, 2022
Fixes vitejs#2443
Fixes vitejs#7454

It's already been set by default in Nuxt 3 for a while now nuxt/framework#6735
So I think this change should be harmless.
And technically it could be considered a fix than a feat.

Nevertheless, it's better to ship it in v4 to minimize disruptions on
the user side.

Things that are not covered in this PR:
1. SSR, because `resolve.dedupe` doesn't work for ESM build outputs, and
the CommonJS version is kinda hacky, I think it's better to skip the
config for SSR completely. Besides, most related issues are from the
client side.
2. #5958 isn't fixed by this PR.
patak-dev pushed a commit that referenced this issue Nov 22, 2022
fc pushed a commit to fc/vite that referenced this issue Nov 23, 2022
patak-dev pushed a commit to vitejs/vite-plugin-vue that referenced this issue Dec 2, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants