pinia store in library mode doesn't work #2487
Replies: 4 comments 2 replies
-
I also have such a problem here, have you solved it? |
Beta Was this translation helpful? Give feedback.
-
I encountered the same issue and resolved it by passing the active Pinia store to the defined store as param, in your case in the reproduction, to the It seems that the problem may be related to how Vite resolves dependencies. Vite locates the nearest dependency to its root, and since Pinia is included in both the "my-app" and "my-lib" folders, it might be causing conflicts when importing a store from a other vite project / build. To troubleshoot this theory, consider removing Pinia from both projects and adding Pinia to the parent directory, placing it alongside "my-app" and "my-lib." as a shared dependency. Alternatively, consider adding an alias to both Vite configurations that targets the pinia dependency in the same node_modules folder. |
Beta Was this translation helpful? Give feedback.
-
You can use vite's shared options resolve.dedupe to resolve this issue import { defineConfig } from 'vite'
export default defineConfig(() => {
return {
// ...
resolve: {
dedupe: ['pinia'],
},
// ...
}
}) |
Beta Was this translation helpful? Give feedback.
-
Maybe this helps. https://pinia.vuejs.org/core-concepts/outside-component-usage.html |
Beta Was this translation helpful? Give feedback.
-
Reproduction
https://github.com/aumaOne/vite-pinia-library
Steps to reproduce the bug
run
npm run build && npm link
onmy-lib
run
npm link my-lib && npm run build && npm run preview
onmy-app
Expected behavior
build/preview would work the same as dev.
Actual behavior
All works fine when running with
npm run dev
but when usingnpm run build && npm run preview
I'm getting a runtime error on the pageAdditional information
It seems that the lib can't access the pinia instance when it is built. pinia.mjs
Beta Was this translation helpful? Give feedback.
All reactions