Timmsy
Timmsy

Reputation: 75

Laravel 9.1 / Vite - "TypeError: laravel is not a function" When Running "NPM Run Dev"

I am attempting to build a web app using Laravel 9.1 which comes with Vite, personally I've never used Vite before so I'm not too sure about this error.

I seem to be receiving the error

TypeError: laravel is not a function

whenever I run npm run dev. I get the same error when running build.

Below I will post my package.json & my vite.config.js files.

Package.json

{
    "type": "module",
    "private": true,
    "scripts": {
        "dev": "vite",
        "build": "vite build"
    },
    "devDependencies": {
        "@vitejs/plugin-vue": "^2.3.3",
        "axios": "^1.1.2",
        "laravel-vite-plugin": "^0.7.1",
        "lodash": "^4.17.19",
        "postcss": "^8.1.14",
        "vite": "^3.2.4"
    },
    "dependencies": {
        "got": "^11.8.3",
        "vue": "^3.2.36",
        "vue-loader": "^17.0.1"
    }
}

vite.config.js

import laravel from 'laravel-vite-plugin'

import vue from '@vitejs/plugin-vue'

import { defineConfig } from 'vite'

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
    resolve: {
        alias: {
            '@': '/resources/js',
        },
    },
});


I'm not sure how to fix this error, or proceed with this error occurring when attempting to run dev.

Thanks in Advance for any help :)

I have tried reinstalling the node modules, updating Node to v19 and even fully restarted the project install.

Upvotes: 3

Views: 3891

Answers (1)

Ivan_OFF
Ivan_OFF

Reputation: 347

Try removing

"type" : "module"

From your package.json, it worked for me but i am still investigating the reason behind

Upvotes: 10

Related Questions