MCPcopy
hub / github.com/nuxt/nuxt / useNuxtApp

Function useNuxtApp

packages/nuxt/src/app/nuxt.ts:578–591  ·  view source on GitHub ↗
(id?: string)

Source from the content-addressed store, hash-verified

576 */
577export function useNuxtApp (): NuxtApp
578export function useNuxtApp (id?: string): NuxtApp {
579 // @ts-expect-error internal usage of id
580 const nuxtAppInstance = tryUseNuxtApp(id)
581
582 if (!nuxtAppInstance) {
583 if (import.meta.dev) {
584 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/4.x/guide/concepts/auto-imports#vue-and-nuxt-composables`.')
585 } else {
586 throw new Error('[nuxt] instance unavailable')
587 }
588 }
589
590 return nuxtAppInstance
591}
592
593/** @since 3.0.0 */
594/* @__NO_SIDE_EFFECTS__ */

Callers 15

pageToClientOnlyFunction · 0.90
setupFunction · 0.90
setupFunction · 0.90
injectHeadFunction · 0.90
setupFunction · 0.90
scrollBehaviorFunction · 0.90
definePageMetaFunction · 0.90
useAppConfigFunction · 0.90
setupFunction · 0.90
setupFunction · 0.90
setupFunction · 0.90
setupFunction · 0.90

Calls 1

tryUseNuxtAppFunction · 0.85

Tested by 1

testFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…