Vue cannot find the #app element it was told to mount on
Your error
[Vue warn]: Failed to mount app: mount target selector "#app" returned null.2 more lines it can showFix it fast
Most common cause, 1 of 2The bundle runs before the element has been parsed
Add defer to the script tag, or load an ES module build with type="module", which defers by default.
<!-- Laravel Mix layout -->
<script src="{{ mix('js/app.js') }}" defer></script>
<!-- plain HTML -->
<script defer src="/js/app.js"></script>Short answer
[Vue warn]: Failed to mount app: mount target selector "#app" returned null, or Cannot find element: #app in Vue 2, means document.querySelector found nothing when mount() ran. Either the script runs before the element is parsed, or this page has no element matching the selector. Load the bundle with defer or type="module", or fix the selector. Vue 3.5.
Which cause do you have?
On the failing page, after it has loaded, ask the console whether the element exists and how the bundle is loaded. A count of 1 with the bundle in the head and neither defer nor module points to cause 1; a count of 0 points to cause 2.
document.querySelectorAll('#app').length
[...document.scripts].map((s) => ({ src: s.src, defer: s.defer, type: s.type, inHead: s.parentNode === document.head }))Then find the line you see in this list and open its fix:
- 1The bundle runs before the element has been parsed
The console count is 1 once the page is loaded, and the app's script tag sits in the head with defer false and no type="module" - 2No element on this page matches the selector
The console count is 0, or the selector inside the warning differs from the id in the HTML (for example "app" without the #)
What does the error look like?
[Vue warn]: Failed to mount app: mount target selector "#app" returned null.[Vue warn]: Cannot find element: #appThe page stays empty in a production build, with nothing in the console
Cause 1 of 2
The bundle runs before the element has been parsed
You seeThe console count is 1 once the page is loaded, and the app's script tag sits in the head with defer false and no type="module"
Check
The mount warning appears here because of timing, not markup. MDN describes a classic script without async, defer or type="module" as fetched and run immediately, before the browser parses the rest of the page. From the head, the bundle calls mount() while the body, and the #app div with it, does not exist yet. Vue 3 then reports the null result of document.querySelector; Vue 2 warns Cannot find element and mounts into a new detached div, so nothing appears on screen.
grep -n "<script" resources/views/layouts/app.blade.php public/index.html 2>/dev/nullFix
Add defer to the script tag, or load an ES module build with type="module", which defers by default. Moving the tag to the end of the body works too.
<!-- Laravel Mix layout -->
<script src="{{ mix('js/app.js') }}" defer></script>
<!-- plain HTML -->
<script defer src="/js/app.js"></script>Verify
Reload: the warning is gone and the container now holds the rendered app.
document.querySelector('#app').children.length > 0Confirmed by developer.mozilla.org
Cause 2 of 2
No element on this page matches the selector
You seeThe console count is 0, or the selector inside the warning differs from the id in the HTML (for example "app" without the #)
Check
mount() takes a CSS selector or a DOM element, and with a string Vue 3 passes it to document.querySelector. A shared layout that loads the bundle on pages without the container, an id spelled differently in the template (root instead of app), or a selector missing its # (which looks for an <app> tag) all return null and produce this warning.
grep -rn "mount(" resources/js src 2>/dev/nullFix
Make the selector and the id match. When one bundle serves many pages and only some have a container, look the element up yourself and mount only when it exists.
import { createApp } from 'vue'
import App from './App.vue'
const el = document.querySelector('#app')
if (el) {
createApp(App).mount(el)
}Verify
Pages with the container render the app, and pages without it log no Vue warning.
document.querySelectorAll('#app').lengthConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Load the app bundle with defer, or as a module, from the head, so the whole body exists before mount() runs.
- In a bundle shared by many templates, pass mount() an element you looked up and skip mounting when it is null.
- Test the page with a development build: Vue 3 emits this warning only in development, so production just shows an empty page.
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.