Cannot use Pinia stores in Nuxt layers: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"? #3033
Unanswered
okainov
asked this question in
Help and Questions
Replies: 2 comments
-
@posva could you please clarify why this is not an issue? Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
-
While I played around with the reproducer for #3028, I was really surprised that it would work if I fix the imports thingy. So I digged deeper and seems like I found what was causing the issue Problematic code: import { defineStore } from 'pinia'
export const useTestStore = defineStore('test', () => { Working code: //import { defineStore } from 'pinia'
export const useTestStore = defineStore('test', () => { Yes, if I remove import @posva do you really think it's not a bug? Did I miss some documentation saying "do not use imports in layers" or something similar? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Reproduction
https://github.com/okainov/pinia-nuxt-layers-bug-repro
Summary
I'm observing the issue when stores are defined and working well in the base layer (as well as in
.playground
), it does NOT work at all with the app extending the layer. The error I'm getting isSteps to reproduce the bug
0 .
piniatest
layer was initialized asnpx nuxi init -t layer piniatest
and one testuseTestStore
composable was created. Information about it added toHelloWorld
componentcd piniatest && npm i && npm run dev
- it starts, opens the page correctly where you can manipulate the store. Works as expectedmainapp
folder - simple example reusing the layer. Do the samecd mainapp && npm i && npm run dev
. Open the page in browserWhen you try to open it, error message appears:
[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"? See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help. This will fail in production.
Expected behavior
It should work the same way as in the main layer
Actual behavior
When you try to open it, error message appears:
[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"? See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help. This will fail in production.
Additional information
I used
composables
folder for store just to avoid issues with imports and extra configuration, seems like there are existing issues about it: at least#3028, #2996
Beta Was this translation helpful? Give feedback.
All reactions