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

TobiasS's avatar
Level 10

Vite upgrade app.js require / import

Hi!

I'm trying to get Vite to work. All assets are compiled but the vue-components do not render

resources/js/app.js

Vue.component('example-component', require('./components/ExampleComponent.vue').default);

const app = new Vue({
    el: '#app',

});

changed to

import ExampleComponent from './components/EventComponent.vue';

this line is of some reason in IDE (vscode) "transparent" as if not used...

Any ideas why component do not render?

Thx in advance!

0 likes
21 replies
Sinnbeck's avatar

Show the full updated example

I would assume it is something like

import Vue from 'vue';
import ExampleComponent from './components/ExampleComponent.vue';

Vue.component('example-component', ExampleComponent);

const app = new Vue({
  el: '#app',
});
tykus's avatar

This is not enough to globally register a Vue Component...

import ExampleComponent from './components/EventComponent.vue';

... what else have you done?

TobiasS's avatar
Level 10

app.js

import './bootstrap';
import Vue from 'vue'

import ExampleComponent from './components/ExampleComponent.vue';
Vue.component('example-component', ExampleComponent);

const app = new Vue({
    el: '#app',

});

example.blade.php

<x-app-layout>
    Test
    <example-component></example-component>
</x-app-layout>
TobiasS's avatar
Level 10

No errors in console Vue dev-tools do not detect Vue

TobiasS's avatar
Level 10

I've built the assets npm run build

valet is serving the site

TobiasS's avatar
Level 10

js file included build/assets/app.51fd922d.js

last row contains "div",{staticClass:"container"},[n._v(" Example VUE ")])},tO=[],nO=Jx(Zx,eO,tO,!1,null,null,null,null);const rO=nO.exports;Yt.component("example-component",rO);new Yt({el:"#app"});

Sinnbeck's avatar

@TobiasS Can you show your vite config as well? I dont use vue myself so I cannot spot any mistakes in the vue code, but I assume its correct

TobiasS's avatar
Level 10
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue2';
import path from 'path'

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/sass/app.scss',
                'resources/js/app.js',
            ],
            resolve: {
                alias: {
                    '~bootstrap': path.resolve(__dirname, 'node_modules/bootstrap'),
                }
            },
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
});
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

And can you show the layout where you have the div with Id="app" ?

TobiasS's avatar
Level 10

Thx @sinnbeck

There was a problem with the div with Id="app" in the layout file...

(Strange that it worked before with mix... anyway now it works!)

TobiasS's avatar
Level 10

@savage Sorry, I still have some problem with Vite and Vue. Will return to this later, but I still run Mix

Please or to participate in this conversation.