From ac2e4661752186ed3cfc850634e963d3f55752eb Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 15 Apr 2023 14:47:34 +0100 Subject: [PATCH] fix(nuxt): provide more helpful error when instance unavailable (#20289) --- packages/nuxt/src/app/nuxt.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/app/nuxt.ts b/packages/nuxt/src/app/nuxt.ts index 2aa48cc28..fc239088b 100644 --- a/packages/nuxt/src/app/nuxt.ts +++ b/packages/nuxt/src/app/nuxt.ts @@ -441,7 +441,11 @@ export function useNuxtApp () { if (!nuxtAppInstance) { const vm = getCurrentInstance() if (!vm) { - throw new Error('nuxt instance unavailable') + if (process.dev) { + throw new Error('[nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug. Find out more at `https://nuxt.com/docs/guide/concepts/auto-imports#using-vue-and-nuxt-composables`.') + } else { + throw new Error('[nuxt] instance unavailable') + } } return vm.appContext.app.$nuxt as NuxtApp }