Skip to content

Commit

Permalink
feat(warn): improve getActivePinia warning
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Aug 28, 2023
1 parent c74842f commit 4640f09
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/pinia/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,8 @@ export function defineStore(

if (__DEV__ && !activePinia) {
throw new Error(
`[🍍]: "getActivePinia()" was called but there was no active Pinia. Did you forget to install pinia?\n` +
`\tconst pinia = createPinia()\n` +
`\tapp.use(pinia)\n` +
`[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"?\n` +
`See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help.\n` +
`This will fail in production.`
)
}
Expand Down

1 comment on commit 4640f09

@Dev-wonderful
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this error yesterday, but it was because I was trying to use a store in a composable. There were 2 functions in the file that would need the store, so I called useStore at the top of the file, because of the error, which took me a while to figure out, I had to call useStore inside of each function, not the best solution but that's what I thought of at the time.

Anyway, I'm saying this to point out, that a question about using a store outside of a component should be added to the error message, I hope this makes sense.

Please sign in to comment.