Vuetify throws Could not find injected layout when a component mounts
Your error
Error: [Vuetify] Could not find injected layoutFix it fast
Most common cause, 1 of 3The test mounts the component without a layout wrapper
Mount a small wrapper whose template puts your component inside v-layout, register the component there, and pass the Vuetify instance as a global plugin.
import { mount } from '@vue/test-utils'
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
import AppShell from '../AppShell.vue'
const vuetify = createVuetify({ components, directives })
const wrapper = mount(
{ template: '<v-layout><app-shell /></v-layout>' },
{ global: { components: { AppShell }, plugins: [vuetify] } },
)Short answer
[Vuetify] Could not find injected layout is thrown when v-app-bar, v-navigation-drawer, v-main, v-bottom-navigation, v-system-bar or a footer with the app prop renders without a v-app or v-layout ancestor. In Vitest, mount the component inside a v-layout wrapper; in the app, keep those components below v-app. Applies to Vuetify 3.x and 4.3.
Which cause do you have?
Run only the failing test, or open the browser console, and read the component names in the stack trace under the error. A layout part (VAppBar, VNavigationDrawer, VMain, VBottomNavigation, VSystemBar, VFooter) tells you which element lacks a layout parent; a call from your own script setup points at cause 3.
npx vitest run src/components/__tests__/AppShell.spec.ts 2>&1 | grep -A12 "Could not find injected layout"Then find the line you see in this list and open its fix:
- 1The test mounts the component without a layout wrapper
The app runs fine in the browser and only the unit test throws - 2A layout component sits outside v-app in the real app
The browser console shows the error on page load, and the component is in App.vue above or beside v-app, or in a second Vue app created with createApp - 3useLayout() is called in the component that renders v-app
The stack trace points at your own setup code calling useLayout, not at a Vuetify component
What does the error look like?
Error: [Vuetify] Could not find injected layout
Cause 1 of 3
The test mounts the component without a layout wrapper
You seeThe app runs fine in the browser and only the unit test throws
Check
In a unit test, Could not find injected layout appears because mount() renders your component as the root, so nothing above it provides the layout. Vuetify's layout parts read that value from a v-app or v-layout ancestor and throw when it is missing. Vuetify's own testing guide mounts components inside a v-layout for this reason.
grep -rn "mount(" src --include=*.spec.ts | headFix
Mount a small wrapper whose template puts your component inside v-layout, register the component there, and pass the Vuetify instance as a global plugin.
import { mount } from '@vue/test-utils'
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
import AppShell from '../AppShell.vue'
const vuetify = createVuetify({ components, directives })
const wrapper = mount(
{ template: '<v-layout><app-shell /></v-layout>' },
{ global: { components: { AppShell }, plugins: [vuetify] } },
)Verify
The test passes and wrapper.html() contains the app bar or drawer markup.
npx vitest run src/components/__tests__/AppShell.spec.tsConfirmed by raw.githubusercontent.com
Cause 2 of 3
A layout component sits outside v-app in the real app
You seeThe browser console shows the error on page load, and the component is in App.vue above or beside v-app, or in a second Vue app created with createApp
Check
Vue's provide and inject only pass values down to descendants, so a v-app-bar or v-main placed next to v-app, or rendered by a separate app instance, cannot see the layout. A v-footer counts only when it has the app prop, because Vuetify registers the footer as a layout item just in that case.
grep -n "<v-app\|<v-layout\|<v-app-bar\|<v-main\|<v-footer" src/App.vue src/layouts/*.vueFix
Make v-app the outermost element of the root component and put every layout part inside it. For a footer that should not take part in the layout, drop the app prop.
<template>
<v-app>
<v-app-bar title="Shop" />
<v-navigation-drawer />
<v-main>
<router-view />
</v-main>
<v-footer app>Footer</v-footer>
</v-app>
</template>Verify
The page loads without the error and v-main leaves room for the app bar.
npm run devConfirmed by raw.githubusercontent.com
Cause 3 of 3
useLayout() is called in the component that renders v-app
You seeThe stack trace points at your own setup code calling useLayout, not at a Vuetify component
Check
When useLayout() itself throws Could not find injected layout, the call is usually made in the same component whose template holds v-app. That component is the provider's parent, not its child, so the layout does not exist for it yet. Vuetify's layout guide warns that the call must happen in a child component.
grep -rn "useLayout()" srcFix
Move the code that reads layout sizes into a component rendered inside v-app, and call useLayout() there.
<!-- LayoutInfo.vue, used inside <v-main> -->
<script setup>
import { useLayout } from 'vuetify'
const { mainRect } = useLayout()
</script>
<template><span>{{ mainRect }}</span></template>Verify
The child component renders the layout values and the root no longer throws.
npm run devConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Keep one test helper that mounts components inside v-layout with the Vuetify plugin, and use it in every component test.
- Put v-app only in App.vue or a layout file, and review any new createApp call for a missing v-app root.
- Add the app prop to v-footer only when the footer should reserve space in the layout.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.