Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel VueJs Vite: Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle?

I'm using vite in my laravel project but when I run npm run build shows me errors in the syntax and the syntax sounds correct.

- my component enter image description here

- my vite.config.js enter image description here

- the error that I see enter image description here

larave ^9.19
vue ^3.2.30
vite ^3.0.0

how I can fix that? and thanks in advance.

like image 531
Abdelkhalek Haddany Avatar asked Dec 05 '25 06:12

Abdelkhalek Haddany


1 Answers

This might be helpful for future nobs like me. I have also faced the same issue with Fresh Laravel 9 and inertia JS. I have tried all solutions and this works for me.

npm i @vitejs/plugin-vue

Open vite.config.js and write vue() function before Laravel

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue"; //add this line
import laravel from "laravel-vite-plugin";

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

then

npm run dev

Hope it will help.

like image 53
Marsad Akbar Avatar answered Dec 07 '25 20:12

Marsad Akbar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!