Pinia · PINIA0006

Call stores inside setup or functions, not at module scope

Report useXStore() calls that run when a module is first imported instead of inside setup, a composable, an action, or a callback.
PINIA0006vite-doctor/piniastoreswarnNo fix

Run this rule

pnpm vite-doctor . --rules pinia/stores/no-module-scope-store

Why it matters

useXStore() finds its Pinia instance through the current app's injection context, falling back to the active Pinia. At module scope there is no app context: before app.use(pinia) runs, Pinia throws "getActivePinia()" was called but there was no active Pinia, and with server-side rendering the module runs once per server process, so every request shares the store it got.

Move the useXStore() call into the function that needs the store: <script setup>, setup(), a composable, a store action, a router guard, or a Nuxt plugin or middleware callback.

Example

Call the store inside the guard that uses it

Before

const user = useUserStore()

router.beforeEach((to) => {
  if (to.meta.requiresAuth && !user.isLoggedIn) return '/login'
})

After

router.beforeEach((to) => {
  const user = useUserStore()
  if (to.meta.requiresAuth && !user.isLoggedIn) return '/login'
})
Copyright © 2026