question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build failing when pinia store is used in modules

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
isokosancommented, Sep 17, 2021

That did the trick!

1reaction
sibbngcommented, Sep 17, 2021

Try awaiting router only on server side with if (!ctx.isClient)

export const createApp = ViteSSG(
  App,
  { routes },
  async(ctx) => {
    if (!ctx.isClient)
      await ctx.router.isReady()

    // install all modules under `modules/`
    Object.values(import.meta.globEager('./modules/*.ts')).map(i => i.install?.(ctx))
  },
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't use vue-router and pinia inside a single store
They can't be used at the module route, and are often used within component setup functions and store actions. You don't need to...
Read more >
Using a store outside of a component - Pinia
The easiest way to ensure this is always applied is to defer calls of useStore() by placing them inside functions that will always...
Read more >
Module: pinia
Doesn't fail on access with strings, making it much easier to write generic functions that do not care about the kind of store...
Read more >
Introduction - Pinia
A timeline to track actions, mutations; Stores appear in components where they are used; Time travel and easier debugging. Hot module replacement.
Read more >
Pinia not installed? : r/vuejs - Reddit
Did you forget to install pinia? const pinia = createPinia() app.use(pinia) This will fail in production. at useStore ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found