【问题标题】:Laravel 9.1 / Vite - "TypeError: laravel is not a function" When Running "NPM Run Dev"Laravel 9.1 / Vite - \"TypeError: laravel is not a function\" 当运行\"NPM Run Dev\"
【发布时间】:2022-12-20 01:35:05
【问题描述】:

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

我似乎收到了错误

TypeError: laravel is not a function

每当我运行 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"
    }
}

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


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

在此先感谢您的帮助:)

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

【问题讨论】:

    标签: javascript node.js laravel npm vite


    【解决方案1】:

    尝试删除

    "type" : "module"
    

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

    【讨论】:

      猜你喜欢
      • 2021-06-02
      • 2018-12-31
      • 2023-01-05
      • 2021-05-25
      • 2021-08-06
      • 2022-07-21
      • 2020-12-18
      • 1970-01-01
      • 2021-06-25
      相关资源
      最近更新 更多