Pinia module causing [500] internal server error after upgrading to Nuxt version to 3.15.x #2901
-
Reproductionhttps://stackblitz.com/edit/github-6p4rt1bq Steps to reproduce the bugNo specific steps required as when the app starts I am getting [nuxt] [request error] [unhandled] [500] [🍍]: "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 behaviorIt shouldn't produce any errors as I am using just a plain starter template with export const useCounterStore = defineStore("counter", () => {
const count = ref(0)
const name = ref("Eduardo")
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
}
return { count, name, doubleCount, increment }
}) and then using it in app.vue <template>
<div>
<NuxtRouteAnnouncer />
<NuxtWelcome />
</div>
</template>
<script lang="ts">
const store = useCounterStore()
</script>
with clean nuxt.config.ts // https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-11-01',
devtools: { enabled: true },
modules: ['@pinia/nuxt']
}) Actual behaviorIn the console I am getting twice [nuxt] [request error] [unhandled] [500] [🍍]: "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 informationThe error started to show when I upgraded Nuxt version from 3.14.x to 3.15.0. I tried every new Nuxt version since, but with the same result. I tried to isolate the pinia module and created empty project from the starter template and the problem persists, so there is no module conflict. At first I thought that it is a Nuxt issue, so I created an issue in their repo (nuxt/nuxt#30751), but the Nuxt team said, it is probably a Pinia (or Pinia nuxt module) issue (nuxt/nuxt#30751 (comment)). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You are using a regular script instead of a setup one: <script lang="ts" setup>
const store = useCounterStore();
</script> The issue you are falling is in the link mentioned in the warning, https://pinia.vuejs.org/core-concepts/outside-component-usage.html |
Beta Was this translation helpful? Give feedback.
You are using a regular script instead of a setup one:
The issue you are falling is in the link mentioned in the warning, https://pinia.vuejs.org/core-concepts/outside-component-usage.html