-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Awaiting a function then awaiting useAsyncData
throws "nuxt instance unavailable" error - but only in a composable
#19724
Comments
useAsyncData
throws "nuxt instance unavailable" error - but only in a composuseAsyncData
throws "nuxt instance unavailable" error - but only in a composable
I think you can see more about the reason here in https://nuxt.com/docs/guide/concepts/auto-imports#using-vue-and-nuxt-composables. Basically, a rule of thumb is that you cannot Outside of those environments, you must use |
Thanks for the fast reply and thorough information. I'll take a look at |
To confirm, our own composables called from within |
Yes. The reason those environments are protected is that we (Vue for |
Environment
Darwin
v18.1.0
3.3.1
2.3.1
pnpm@7.25.0
vite
-
-
-
Reproduction
https://github.com/Jamiewarb/nuxt-useasync-repro
pnpm install && pnpm dev
'~/composables/useTest'
contains two functions, the difference being the lines swapped around. One works, and one doesn't, so you can see both.Copying the non-working function directly into the <script> tag of
app.vue
means it starts working again.Describe the bug
Within a component, when calling a function that uses
await
, there is a bug that appears depending on the order of the await's. I assume this is to do with the compiler and Nuxt's composables, but I'm not sure how to describe it.The below doesn't work, and throws a
nuxt instance unavailable
:But swapping the order is fine:
Furthermore, taking the non-working code and putting it directly into a component
<script setup>
means it works again:Additional context
No response
Logs
The text was updated successfully, but these errors were encountered: