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.

Vue3 lib not working in Vue2 projects

See original GitHub issue

First of all, I saw a couple of issues that involved more or less the same issue, but I tought it would be useful to group everything into one issue, so we could hopefully try to solve it.

Related issues:

Problem

I’m currently building a private reusable package for a real-world application. This application runs on nuxt2 (currently nuxt-bridge), and we’re planning to migrate to nuxt3 when all the packages we need are there. The idea was to build that reusable package in vue3, and use vue-demi to make it possible to be used in our nuxt-bridge app.

At first I just tried building the library and use it in a separate vue 3 app. With Vite it was really fast & easy to make it work 🎉

However when I tried importing it in our nuxt-bridge app I came across several issues:

  1. When externalising vue dependency in vite, I got a list of warnings that some functions are not exported by vue. This is what the most issues are about.

  2. When I don’t externalise vue in vite.config.js, I just get an empty component. In my repro I don’t get any warning. I just see an anonymous component in my dev tools. In my production nuxt-app, I see the following error: no template or render function is defined. The component seemed to be imported correctly, it just doesn’t render any HTML.

  3. I saw in other issues that the solution might be to externalise vue-demi as well, but that doesn’t seem to make any difference for this.

  4. also tried using npx vue-demi-fix && npx vue-demi-switch 2 commands, but these also doesn’t seem to be changing a whole lot.

I also saw that in #117 , @koooge researched into the issue a bit and saw that it might be due to a breaking change in @vue/core.

That’s when I decided to build a repro with a vue2 app (@vue/cli), vue3 app (vite) and a simple component in a separate lib.

Repro

https://github.com/jclaessens97/vue-demi-vue2-broken-repro

I hope we can look into this issue and try to come up with a solution to be able to make vue3 components compatible for vue2, until everything is vue3 ready.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:11
  • Comments:9

github_iconTop GitHub Comments

3reactions
jclaessens97commented, Apr 15, 2022

@LinusBorg answered me on Discord saying the following:

image

As said, might be useful to have in the README.md to avoid future issues about this topic 😄 I’m coming back on it on Tuesday.

2reactions
GUGIGcommented, Oct 14, 2022

I published a public repo & its npm package. repo link It’s a demo package to showcase how I managed to make a vue component library compatible with both vue 2 & 3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Vue 2 libraries on a Vue 3 project - Stack Overflow
there is a package that I made using vue 2 and I want to import it on my vue 3 project, and it...
Read more >
Make Libraries Working with Vue 2 and 3
The most simple way is to write universal code that works in both versions without any additional modification, just like people would do...
Read more >
I can't import some Libraries in main.ts(TypeScript) in Vue3.js ...
Coding example for the question I can't import some Libraries in main.ts(TypeScript) in Vue3.js project-Vue.js.
Read more >
How to migrate your library from Vue2 to Vue3
Most of Vue plugins and third-party libraries will not work on Vue3 (yet) due to the breaking changes on the Global API see...
Read more >
Building a Vue 3 component library - LogRocket Blog
Basic setup. To create our component library, we will not use the normal scaffolding process of Vue.js projects, i.e., Vue CLI. We'll ...
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