@pinia/nuxt: getActivePinia was called with no active Pinia #806
-
Hi there, I'm getting this error when I run Environment
Error
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Reproduction
|
Beta Was this translation helpful? Give feedback.
-
Okay so I think I figured out the issue that causes this. Not sure if this is directly related to the original post, but since I couldn't understand why it seemed to work in some cases and not others, I finally narrowed it down to a reproducible repo: https://github.com/bencodezen/nuxt-3-sandbox The interesting part is that this error doesn't show up in When you run SolutionIf you're running into this, move any call of another store within the store definition: Badimport { defineStore } from 'pinia'
import { useUserStore } from '~/store/user'
const userStore = useUserStore()
export const useThemeStore = defineStore('theme', {
state: () => ({
name: 'theme-name'
}),
actions: {
setTheme() {
this.name += userStore.name
}
}
}) Goodimport { defineStore } from 'pinia'
import { useUserStore } from '~/store/user'
export const useThemeStore = defineStore('theme', {
state: () => ({
name: 'theme-name'
}),
actions: {
const userStore = useUserStore()
setTheme() {
this.name += userStore.name
}
}
}) |
Beta Was this translation helpful? Give feedback.
-
For anyone else encountering this issue, i have solved it by importing my store using the <script setup>
import { useTest } from "~/store/test";
const test = useTest()
</script> meaning that i added the That or you can perform the initialization in the export default <script>
import { useTest } from "~/store/test";
export default {
setup() {
const test = useTest()
return { test }
},
methods: {
}
}
</script> |
Beta Was this translation helpful? Give feedback.
Okay so I think I figured out the issue that causes this. Not sure if this is directly related to the original post, but since I couldn't understand why it seemed to work in some cases and not others, I finally narrowed it down to a reproducible repo:
https://github.com/bencodezen/nuxt-3-sandbox
The interesting part is that this error doesn't show up in
nuxi dev
at all. It only shows up on build and my guess is that it's likely because of how it's being compiled.When you run
npm run build
on this, this is where you'll see that error appear every time. And from my debugging so far, it's happening when a dev tries to setup a second store and calls it within another outside of the context o…