Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hexman's avatar

ReferenceError: createApp is not defined in Vue3

I get this error: ReferenceError: createApp is not defined at ... in the console.

I use:

  • OS: Windows 10
  • Browser: Chrome Version 105.0.5195.127
  • Version Laravel: 9.19
  • Version VueJs: 3.2.36

vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

import vue from '@vitejs/plugin-vue'

export default defineConfig({
    plugins: [
        vue(),
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js'
            ],
            refresh: true,
        }),
    ],
});

package.json

{
    "private": true,
    "scripts": {
        "dev": "vite",
        "build": "vite build"
    },
    "devDependencies": {
        "axios": "^0.27",
        "laravel-vite-plugin": "^0.6.0",
        "lodash": "^4.17.19",
        "postcss": "^8.1.14",
        "vite": "^3.0.0"
    },
    "dependencies": {
        "vue": "^3.2.36",
        "vue-loader": "^17.0.0",
        "@vitejs/plugin-vue": "^3.1.0"
    }
}

app.js

import './bootstrap';
import {createApp} from 'vue';

welcome.blade.php

<head>
...
</head>
<body>
	<div id="appVue">@{{ message }}</div>
    @vite('resources/js/app.js')						
</body>
   <script>
     createApp({
            data() {
                return {
                    message: 'Hello Vue!'
                }
            }
        }).mount('#appVue')
   </script>

after running npm run dev, everything is ok, I have no errors, but I get this error: ReferenceError: createApp is not defined at ...

0 likes
11 replies
Sinnbeck's avatar

@Hexman Ah ok I see. You want to use it outside of you js files. You need to bind it to the window then

import {createApp} from 'vue';
window.createApp = createApp

The same goes for other things you need access to :)

Hexman's avatar

@Sinnbeck Thanks for your answer, but it doesn't work. I added in app.js: window.createApp = createApp but I get the same error in the console.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Hexman Any change if you set the script as a module?

   <script type="module">
     createApp({
            data() {
                return {
                    message: 'Hello Vue!'
                }
            }
        }).mount('#appVue')
   </script>
Hexman's avatar

@Sinnbeck I tried, the error no longer appears, I receive this message in the console: [Vue warn]: Component provided template option but runtime compilation is not supported in this build of Vue. Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js". at <App>

But the value from the message is not displayed in the blade

Please or to participate in this conversation.