I have a Nuxt3 project with an Api in server/api/<api-endpoints>. Inside an endpoint, when I try to use a Pinia Store it says:
[nuxt] [request error] [🍍]: getActivePinia was called with no active Pinia. Did you forget to install pinia?
or when I try to access a composable function from composables it cannot define any variable (says xxx is undefined even though it works in components so it just can't define anything in the function).
Pinia example inside server/api/token
import { useAuthStore } from "../stores/useAuthStore";
export default async (req: any, res: any) => {
const authStore = useAuthStore()
return authStore.access_token
};
Composable example inside server/api/user
import { useUserLogin } from "../../composables/useUserLogin";
export default async (req: any, res: any) => {
const userLogin = useUserLogin()
return twitchLogin.is_logged_in
};
I solved it by renaming buildModules to modules in nuxt.config.js
Nuxt modules are now build-time-only, and the buildModules property used in Nuxt 2 is deprecated in favor of modules.
// nuxt.config.js
export default defineNuxtConfig({
modules: [
// ...
'@pinia/nuxt',
],
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With