fix(nuxt): provide more helpful error when instance unavailable (#20289)

This commit is contained in:
Daniel Roe 2023-04-15 14:47:34 +01:00 committed by GitHub
parent d48024e71f
commit ac2e466175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}