Pinia with Vue 2.7 and router example #2416
-
Hello. We are migrating legacy code base to Vue 2.7 and in future to Vue 3. One part is pinia store. We are lost in Vue 2.7 and endless errors with getPiniaInstance missing pinia. We are facing errors with missing pinia instance also in stores in random order. Is on the world example , which is running with pinia 2.1.6 and Vue 2.7 + Vue-router? We have to use
In official docu is not example with useXxxStore with passing pinia instance as argument in web browser (only SSR example available). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
This sounds like you have 2 copies of Pinia (or some other vue related library) in your code. Depending on the bundler, you will have to ensure only one is used. For example in Vite, you use the optimizeDeps and dedupe |
Beta Was this translation helpful? Give feedback.
-
Hi. After hours of debugging. There are rules for using pinia, router and vue 2.7 in monorepo worksapces:
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ['vue', 'pinia', ...Object.keys(packageJson.dependencies)],
output: {
exports: 'named',
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
vue: 'Vue',
pinia: 'pinia'
}
},
I think it would be usefull to have documentation about vite configuration and using SSR mode of pinia in SPA. :) |
Beta Was this translation helpful? Give feedback.
Hi. After hours of debugging. There are rules for using pinia, router and vue 2.7 in monorepo worksapces:
use dedupe (maybe helping for something :) )
router have to be created before mounting with $mount…