vuetifyjs/vuetify · error · Error
[Vuetify] ${name} ${message || 'must be called from inside a
Error message
[Vuetify] ${name} ${message || 'must be called from inside a setup function'} What it means
Many Vuetify composables call getCurrentInstance() to assert they run during a component's setup(). Vue's getCurrentInstance returns null outside setup (module scope, plain functions, async callbacks after await, detached event handlers). Vuetify wraps it and throws so such misuse fails loudly rather than silently returning undefined.
Source
Thrown at packages/vuetify/src/util/getCurrentInstance.ts:9
// Utilities
import { getCurrentInstance as _getCurrentInstance } from 'vue'
import { toKebabCase } from '@/util/helpers'
export function getCurrentInstance (name: string, message?: string) {
const vm = _getCurrentInstance()
if (!vm) {
throw new Error(`[Vuetify] ${name} ${message || 'must be called from inside a setup function'}`)
}
return vm
}
export function getCurrentInstanceName (name = 'composables') {
const vm = getCurrentInstance(name).type
return toKebabCase(vm?.aliasName || vm?.name)
}
View on GitHub (pinned to 8d153908df)
Solutions
- Move the composable call into setup(), synchronously and before any await.
- Call the composable once in setup and pass its return value to helper functions.
- For async work, resolve composable results in setup and reference them in the async callback.
Example fix
// before
async function load() {
await fetch('/api')
const theme = useTheme() // throws: past await, instance is null
}
// after
const theme = useTheme() // called in setup
async function load() {
await fetch('/api')
theme.current.value = theme.themes.value.dark
} Defensive patterns
Strategy: type-guard
Validate before calling
import { getCurrentInstance as vm } from 'vue'
export function isInSetup (): boolean {
return vm() != null
}
// before calling a Vuetify composable:
if (!isInSetup()) {
// not safe to call useX(): defer or restructure
} Type guard
import { getCurrentInstance as vm } from 'vue'
export function isInSetup (): boolean {
return vm() != null
} Prevention
- Call composables synchronously at the top of setup().
- Capture composable results in setup and pass them to helpers.
- Never call composables after an await or inside detached callbacks.
When it happens
Trigger: Calling a Vuetify composable (useTheme, useDisplay, useLocale, useLayout, getCurrentInstanceName, etc.) from a plain utility function, top-level module code, an async function after the first await, or a callback detached from setup.
Common situations: Refactoring setup logic into a separate non-setup function; calling composables inside setTimeout/Promise.then/pinia actions; using them after an await in an async setup.
Related errors
AI-assisted analysis of vuetifyjs/vuetify@8d153908df (2026-08-12).
Data as JSON: /api/errors/fb968faa549f8cd8.
Report an issue: GitHub.