Laravel 9.1 / Vite - 运行“NPM Run Dev”时出现“TypeError:laravel 不是函数”

Tim*_*msy 2 javascript node.js npm laravel vite

我正在尝试使用 Vite 附带的 Laravel 9.1 构建一个 Web 应用程序,我个人以前从未使用过 Vite,所以我不太确定这个错误。

我似乎收到错误

TypeError: laravel is not a function
Run Code Online (Sandbox Code Playgroud)

每当我运行 npm run dev 时。运行构建时出现同样的错误。

下面我将发布我的 package.json 和 vite.config.js 文件。

包.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"
    }
}

Run Code Online (Sandbox Code Playgroud)

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',
        },
    },
});


Run Code Online (Sandbox Code Playgroud)

我不确定如何修复此错误,或继续处理尝试运行开发时发生的此错误。

预先感谢您的任何帮助:)

我尝试重新安装节点模块,将节点更新到 v19,甚至完全重新启动项目安装。

Iva*_*OFF 9

尝试删除

"type" : "module"
Run Code Online (Sandbox Code Playgroud)

从你的 package.json 来看,它对我有用,但我仍在调查背后的原因