{"record":{"id":"fb968faa549f8cd8","repo":"vuetifyjs/vuetify","slug":"vuetify-name-message-must-be-called-fro","errorCode":null,"errorMessage":"[Vuetify] ${name} ${message || 'must be called from inside a setup function'}","messagePattern":"\\[Vuetify\\] (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vuetify/src/util/getCurrentInstance.ts","lineNumber":9,"sourceCode":"// Utilities\nimport { getCurrentInstance as _getCurrentInstance } from 'vue'\nimport { toKebabCase } from '@/util/helpers'\n\nexport function getCurrentInstance (name: string, message?: string) {\n  const vm = _getCurrentInstance()\n\n  if (!vm) {\n    throw new Error(`[Vuetify] ${name} ${message || 'must be called from inside a setup function'}`)\n  }\n\n  return vm\n}\n\nexport function getCurrentInstanceName (name = 'composables') {\n  const vm = getCurrentInstance(name).type\n\n  return toKebabCase(vm?.aliasName || vm?.name)\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/vuetifyjs/vuetify/blob/8d153908dffb7592eb389ddbfbab955a0ccc977f/packages/vuetify/src/util/getCurrentInstance.ts#L1-L20","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nasync function load() {\n  await fetch('/api')\n  const theme = useTheme() // throws: past await, instance is null\n}\n\n// after\nconst theme = useTheme() // called in setup\nasync function load() {\n  await fetch('/api')\n  theme.current.value = theme.themes.value.dark\n}","handlingStrategy":"type-guard","validationCode":"import { getCurrentInstance as vm } from 'vue'\nexport function isInSetup (): boolean {\n  return vm() != null\n}\n// before calling a Vuetify composable:\nif (!isInSetup()) {\n  // not safe to call useX(): defer or restructure\n}","typeGuard":"import { getCurrentInstance as vm } from 'vue'\nexport function isInSetup (): boolean {\n  return vm() != null\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["composition-api","setup","lifecycle","vue"],"backgroundTag":null,"analyzedSha":"8d153908dffb7592eb389ddbfbab955a0ccc977f","analyzedAt":"2026-08-12T21:54:20.596Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}