gpt4 book ai didi

laravel - 无法在 Laravel 项目中安装 @vitejs/plugin-vue

转载 作者:行者123 更新时间:2023-12-05 02:27:42 36 4
gpt4 key购买 nike

我创建了一个新的 Laravel 项目。为了使用 Vue JS,我尝试安装这个包,

@vitejs/plugin-vue

但这给我带来了一系列错误,

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @vitejs/plugin-vue@3.0.0
npm ERR! Found: vite@2.9.14
npm ERR! node_modules/vite
npm ERR! dev vite@"^2.9.11" from the root project
npm ERR! peer vite@"^2.9.9" from laravel-vite-plugin@0.4.0
npm ERR! node_modules/laravel-vite-plugin
npm ERR! dev laravel-vite-plugin@"^0.4.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vite@"^3.0.0" from @vitejs/plugin-vue@3.0.0
npm ERR! node_modules/@vitejs/plugin-vue
npm ERR! @vitejs/plugin-vue@"^3.0.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: vite@3.0.0
npm ERR! node_modules/vite
npm ERR! peer vite@"^3.0.0" from @vitejs/plugin-vue@3.0.0
npm ERR! node_modules/@vitejs/plugin-vue
npm ERR! @vitejs/plugin-vue@"^3.0.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

我按照这些步骤,

1.laravel new {proj_name}.



2. npm install vue@next.



3. npm install.



4. After that I created a vue file and imported into app.js (resources/js/app.js).



5. I went to the blade file and cleared all -> hit `!` for emmet snippet, created a div with id #app, and add
@vite('resources/js/app.js').

我抛出一个错误提示安装@vitejs/plugin-vue。但是当我尝试安装它时,它会抛出这些错误。

最佳答案

npm install vue@next vue-loader@next
npm i @vitejs/plugin-vue@2.3.3
composer require innocenzi/laravel-vite:0.2.*
npm i -D vite vite-plugin-laravel

vite.config.js

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import laravel from 'vite-plugin-laravel'

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

也许你需要改变 app.js

import {createApp} from 'vue/dist/vue.esm-bundler.js';

或者为异步组件添加 defineAsyncComponent

import {createApp, defineAsyncComponent} from 'vue/dist/vue.esm-bundler.js';

@vite()留空

关于laravel - 无法在 Laravel 项目中安装 @vitejs/plugin-vue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72995266/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com