Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nuxt 3.7.0 - "getActivePinia()" was called but there was no active Pinia #22943

Closed
CodeDredd opened this issue Sep 1, 2023 · 6 comments · Fixed by #22991
Closed

nuxt 3.7.0 - "getActivePinia()" was called but there was no active Pinia #22943

CodeDredd opened this issue Sep 1, 2023 · 6 comments · Fixed by #22991

Comments

@CodeDredd
Copy link
Contributor

Environment

  • Operating System: Linux
  • Node Version: v16.20.0
  • Nuxt Version: 3.7.0
  • CLI Version: 3.7.3
  • Nitro Version: 2.6.2
  • Package Manager: npm@9.4.2
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-h8hokc?file=app.vue

Describe the bug

Hello,

since 3.7.0 it seems that the pinia instance is initilized in a different order. With nuxt 3.6.5 everything works fine.

Additional context

There is also an issue on my repository for this topic CodeDredd/pinia-orm#1585

Logs

[🍍]: "getActivePinia()" was called but there was no active Pinia. Did you forget to install pinia? const pinia = createPinia() app.use(pinia) This will fail in production.

at Query.commit (./node_modules/pinia-orm/dist/index.js:630:91)
at Query.storeFind (./node_modules/pinia-orm/dist/index.js:833:23)
at Query.select (./node_modules/pinia-orm/dist/index.js:897:23)
at Query.internalGet (./node_modules/pinia-orm/dist/index.js:871:25)
at Query.get (./node_modules/pinia-orm/dist/index.js:850:19)
at Repository.all (./node_modules/pinia-orm/dist/index.js:1566:25)
at setup (./app.js:15:28)
at _sfc_main.setup (./app.js:30:23)
at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:156:18)
@stackblitz
Copy link

stackblitz bot commented Sep 1, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@danielroe
Copy link
Member

Possibly related: #22918

@vinothkbest
Copy link

Yes. I think below works

import { defineStore, createPinia, setActivePinia } from "pinia"
const pinia = createPinia()

export default { store: setActivePinia(pinia) }
export const useMainStore = defineStore("main", {

@CodeDredd
Copy link
Contributor Author

Yes. I think below works

import { defineStore, createPinia, setActivePinia } from "pinia"
const pinia = createPinia()

export default { store: setActivePinia(pinia) }
export const useMainStore = defineStore("main", {

It's not about a general vue project there i need to create Pinia store by my own. Here @pinia/nuxt is used which already creates the pinia instance.
But somehow the pinia instance isn't created before setup is called which was different in nuxt 3.6.5.
The workarounds that work are already mentioned in this ticket: CodeDredd/pinia-orm#1585

@vinothkbest
Copy link

Yes. Says in nuxt only. In store folder.

@MateuszStawski
Copy link

Yes. I think below works

import { defineStore, createPinia, setActivePinia } from "pinia"
const pinia = createPinia()

export default { store: setActivePinia(pinia) }
export const useMainStore = defineStore("main", {

It's not about a general vue project there i need to create Pinia store by my own. Here @pinia/nuxt is used which already creates the pinia instance. But somehow the pinia instance isn't created before setup is called which was different in nuxt 3.6.5. The workarounds that work are already mentioned in this ticket: CodeDredd/pinia-orm#1585

nuxt 3.11.2, had to use the same workaround, it doesn't seem to be fixed with more current versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants