vite-ssg: Build failing when pinia store is used in modules
Please check this issue here, its either pinia related or vite-ssg - but in any case I couldn’t figure out the best way to install global middleware that uses the store, that doesn’t throw this error on build.
Any suggestions on how to access the store in a router.beforeEach
, which is initialized with the app?
And in case the store uses localStorage initialization which won’t be available during generation, any best practices there?
Would be great if one could direct me to an example repo with such middleware.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 22 (1 by maintainers)
That did the trick!
Try awaiting router only on server side with
if (!ctx.isClient)
Probably you are trying to access pinia store before it’s getting installed or; registered another router hook on other modules.
Try putting
await router.isReady()
onmain.ts
like that:This would fix your issue if you are trying to access pinia store on other modules.