vite-plugin: TypeError: laravel is not a function

  • Laravel Vite Plugin Version: 0.7.2
  • Laravel Version: 9.4.0
  • Node Version: 16.18.1
  • NPM Version: 8.19.2
  • Host operating system: Windows
  • Web Browser & Version: Chrome 108.0.5359.124
  • Running in Sail / Docker: Docker

Description:

I’m using Laravel 9.x along with Inertia (Svelte). There is an issue when running npm run dev: error when starting dev server: TypeError: laravel is not a function.

Steps To Reproduce:

Bellow is vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/js/app.js'],
            refresh: true,
        }),
        svelte({
            prebundleSvelteLibraries: true,
        }),
    ],
    
    optimizeDeps: {
        include: [
            '@inertiajs/inertia',
            '@inertiajs/inertia-svelte',
            "@inertiajs/progress",
        ]
    }
});

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

As a temporary fix, you may specify "type": "module" in the package.json and then when you reference the laravel function, instead reference laravel.default.

We will investigate a fix for this.

e.g.

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { svelte } from '@sveltejs/vite-plugin-svelte';

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

@fpolli I see you’re using

"type": "module",

That’s not a valid setting for a Laravel app. Please revert that and try again. @lrfahmi are you also using that?