Libraries compiled with 3.0.8 may be incompatible with 3.0.7
Version
3.0.8
Reproduction link
https://gitlab.com/rm-issues/v3.0.8-using-plugin-fails
Steps to reproduce
Clone the repository.
Run npm serve
Open localhost:8080
Check dev console
What is expected?
The Home view from the basic setup should be displayed correctly when using an external library.
What is actually happening?
If you use version 3.08. vue cannot be loaded in the external library. Instead when trying to import anything from vue in App.vue you will be getting the error
Uncaught TypeError: Object(...) is not a function
I am the creator of vue-mapbox-ts and up until this morning everything worked out well. But this morning it stopped to work. After some digging I found that for my test page I was still using an cdn import and vue had been updated to version 3.0.8. 3.0.7 was (and is) running just fine.
I tried to boil down the problem to the minimal changes based on a default vue application created by @vue/cli and this is what I did
- vue create (with default settings)
- install my library using npm
- add the use to main.ts
I did not use any components from that library and left the App.vue as it was so there are no more changes to the basic installation. However the error
Uncaught TypeError: Object(...) is not a function
will be thrown in App.vue when trying to import defineComponent (or anything else for that matter) from "vue"
Now usually this happens if I mess up something with my externals when I am testing component libraries and multiple instances of vue are present but this is not the case here. The plugin just registers some components. Everything is still working fine with 3.0.7.
Now I am still getting into some of the details of creating component libraries in vue3 and my implementation might not be perfect. However I think that with just new patch release 3.0.7 -> 3.0.8 vue should behave in the same manner.
Just for testing I also tried importing vue from a cdn and defining the externals in my webpack config to rule out this reason but the outcome is the same
You should rebuild your project(vue-mapbox-ts
) with vue 3.0.8's compiler. In 3.0.8, we refactored the runtime implementation of scope style, it has no changes to the user-side API, but for library authors, you must rebuild your library with vue 3.0.8's new compiler, otherwise it cannot be used for 3.0.8+
@HcySunYang Then this is a breaking change introduced in a patch release.
That's not really what we want to do unless absolutely necessary in terms of bug fixing, I would say.
We should discuss this in the team, re-evaluate the real impact of this on lib maintainers and come up with a strategy to handle this situation.
That's not really what we want to do unless absolutely necessary in terms of bug fixing
This is a necessary refactoring for slot scope id, see https://github.com/vuejs/vue-next/pull/3374, yes, this is a breaking change for library authors.
I just realized that the build resources of vue-mapbox-ts
contain outdated code:
So I think it must be that the version of the vue compiler used by the library author is lower than 3.0.8
Still, if it's breaking a ton of libs, we should consider rolling this back, communicating the change with the community and give them time to prepare.
Because at the end, it's not only affecting lib authors, it would break many apps that use a lib that was compiled with a compiler version <3.0.8
, with no clear reason that the app's developers could infer.
I agree, but this is actually a problem that must occur during dev or build process. Users should be easy to detect and it does not seem to bring hidden risks to users.
Thanks for the quick reply. That was indeed the problem. Since in my test project (where I am actually importing the source from my library) I was adding vue from cdn but using the compiler version 3.0.7 this did not work. And importing the built version did not work as it was compiled using an older version.
Now I am just caught up a little. I have to use rollup to bundle this lib even tough I would happily use vite because I have to use it in projects that are dependent on vue2 and cannot be updatet to vue3 just jet because of dependency issues. And while vite is not as far as I know able to build Vue2 Apps the current rollup vue plugin (I guess this is the one compiling vue for rollup?) does not implement the new compiler yet. (beta 10 depends on 3.0.0-rc.5)
This should not be your concern and does not affect this issue but it may affect others that try to maintain component libraries using the power of vue3 but still beeing able to make those libraries work in vue2.
Anyway thanks for the quick reply again. Always amazed how active this community is even on a saturday ;)
As an afterword, it seems that this PR(https://github.com/vuejs/vue-next/pull/3334) will encounter the same situation, since https://github.com/vuejs/vue-next/pull/3334 has been marked as a plan for 3.1, maybe we can introduce these changes together in 3.1 ?
I agree, but this is actually a problem that must occur during dev or build process. Users should be easy to detect and it does not seem to bring hidden risks to users.
Yes, people upgrading to 3.0.8 will likely find this bug during build, and can then roll back to 3.0.7.
Still, this is problematic. 3.0.8
brings a ton of other important bug fixes that people now can't use until all their dependencies have upgraded to a version compiled with the 3.0.8 compiler.
Disclaimer We still need to figure out how broad the effect of the issue is.
@relief-melone this is not really an issue for vite itself. you can upgrade the compiler in a vite project as well, it's not hardcoded to 3.0.7 or anything.
I'll also reopen this issue as for us, it's not resolved.
maybe we can introduce these changes together in 3.1 ?
Would be a better strategy. Also gives us to to rethink how to introduce the change while creating as little friction as possible.
rollup-plugin-vue
supports all compiler versions:
https://github.com/vuejs/rollup-plugin-vue/blob/next/package.json#L26
you just have to make sure that the compiler installed in the project is for 3.0.8.
But before doing that maybe wait a bit until we can communicate clearly how we proceed with this issue.
This would still only be an issue for users that also publish their vue3 libraries for vue2
Vue 2 isn't affected by this at all as the compiler change only affects Vue 3 projects.
OK updating the compiler manually to 3.0.8 also seems to work for the rollup plugin (probably just forgot to npm serve again the first time). The only thing that I noticed is that backward compatiblity would also be an issue. So if I compile my library with 3.0.8 but leave my test environment on 3.0.7 this will also result in the same error