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

Keep getting "getActivePinia()" was called but there was no active Pinia error #93

Closed
ymansurozer opened this issue Nov 2, 2024 · 5 comments

Comments

@ymansurozer
Copy link

I wanted to give Pinia Colada a try because it really looks great!

But immediately after I do the setup and try to use useQuery, I get the error in the title. I am not calling Pinia anywhere at all and the stack shows it is being called in Colada. I have a very simple app.vue:

<script lang="ts" setup>
import type { Todo } from '~/types';
import { useQuery } from '@pinia/colada';

const newTodo = ref('');

const { data: todos } = useQuery({
  key: ['todos'],
  query: () => $fetch<Todo[]>('/api/todos'),
});
</script>

<template>
  <div>
    <div>
      <input v-model="newTodo" />
    </div>

    <h2>Todos</h2>
    <pre>{{ todos }}</pre>
  </div>
</template>

Here is a reproduction: https://stackblitz.com/edit/github-xmm1oh?file=app.vue

@posva
Copy link
Owner

posva commented Nov 3, 2024

See vuejs/pinia#2820

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2024
@github-project-automation github-project-automation bot moved this from 🆕 Triaging to Done in Pinia Colada Roadmap Nov 3, 2024
@ymansurozer
Copy link
Author

ymansurozer commented Nov 3, 2024

Thanks for the prompt response Eduardo! Excluding pinia from Vite's optimizeDeps solved it for me.

The weird thing is my reproduction is neither a monorepo nor uses pnpm. It is a bare-bones Nuxt project with npm as package manager.

Edit: I keep getting the following warning on the console, is it related to this as well?

Found a nullish hmr id. This is probably a bug. Please report it to pinia-colada with a boiled down reproduction. Thank you!

Sorry if I'm being too picky but we're trying Colada as an alternative to Tanstack Query for a relatively big project and warnings make me a bit worried.

Copy link
Owner

posva commented Nov 3, 2024

There are a few issues related to Nuxt (or vite) and deps. I recommend you to add @pinia/colada to the exclude array alongside pinia too 🙂
That warning is fixed but not released yet. it's just that, a warning that shouldn't be shown. It's also only about HMR, so dev only. Nothing to worry.

@posva
Copy link
Owner

posva commented Nov 3, 2024

FYI, the latest @pinia/nuxt module should fix the issue

@ymansurozer
Copy link
Author

Thank you very much Eduardo!

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

No branches or pull requests

2 participants