vueuse / vue-demi

🎩 Creates Universal Library for Vue 2 & 3
MIT License
2.99k stars 158 forks source link

.use is not a function #175

Open jak-hammond opened 2 years ago

jak-hammond commented 2 years ago

I am attempting to use Pinia inside a Vue 2.6.14 app, I have followed the steps outline by Pinia to install the Vue Composition API plugin but when the app loads, a piece of code inside Vue Demi is throwing and after taking a look it seems to be that in the case of the Vue 2, the default property needs to be first accessed before the use function can be called.

image

image

jak-hammond commented 2 years ago

Did some digging and found a similar issue on the .cjs file previously which is now successfully detecting the presence of defualt so it seems it might be a case of implementing that same check in here. I did a quick and dirty check in my own app by simply referencing default directly and it successfully installs the composition API....obviously that isn't robust like the fix for the prior issue but it does seem to suggest the same root cause.

image

This seems to be related to Webpacks Module Federation and loading in another Vue app, so potentially an issue conflicting with how the Vue instance is being loaded from there.

promer94 commented 2 years ago

I have the same issus Repro: https://github.com/promer94/demi-mf-bug

promer94 commented 2 years ago

This problem is more like a webpack bug or capability issue https://github.com/webpack/webpack/issues/16060

promer94 commented 2 years ago

Find a workaroud for this problem.

For vue < 2.7

npx vue-demi-switch 2 vue/dist/vue.runtime.esm.js could change the entry.

Dreamer-Somebody commented 1 year ago

For me,set webpack alias can solve the problem;

alias: {
    'vue-demi': 'vue-demi/lib/v2/index.cjs',
}

then clear webpack cache(./node_modules/.cache)and reboot your project.