![](/img/trans.png)
[英]Laravel 9.1 / Vite - "TypeError: laravel is not a function" When Running "NPM Run Dev"
[英]error occured when do npm install && npm run dev - Vite - Laravel UI React
大家好,今天我遇到了一個問題,當我安裝laravel ui 和 react並傳遞到npm 安裝的步驟時發生錯誤,所以您會在下面找到錯誤
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\E495\AppData\Local\npm-cache\_logs\2023-01-16T08_08_36_872Z-debug-0.log
PS C:\Users\E495\Desktop\laravel-simple-crud> npm install
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: vite@4.0.4
npm ERR! node_modules/vite
npm ERR! dev vite@"^4.0.4" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vite@"^3.0.0" from @vitejs/plugin-react@2.2.0
npm ERR! node_modules/@vitejs/plugin-react
npm ERR! dev @vitejs/plugin-react@"^2.2.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.
npm ERR!
npm ERR! See C:\Users\E495\AppData\Local\npm-cache\eresolve-report.txt for a full report.
所以在錯誤上方和下方你會找到我的package.json
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"@popperjs/core": "^2.11.6",
"@tailwindcss/forms": "^0.5.2",
"@vitejs/plugin-react": "^2.2.0",
"alpinejs": "^3.4.2",
"autoprefixer": "^10.4.2",
"axios": "^1.1.2",
"bootstrap": "^5.2.3",
"laravel-vite-plugin": "^0.7.2",
"lodash": "^4.17.19",
"postcss": "^8.4.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.56.1",
"tailwindcss": "^3.1.0",
"vite": "^4.0.4"
}
}
我嘗試讀取錯誤並將vite版本更改為4.0.4但沒有任何結果
您應該能夠使用以下命令解決此錯誤:
npm install --legacy-peer-deps
上一篇文章詳細介紹了--legacy-peer-deps
在這里做什么。
簡而言之, @vitejs/plugin-react
(特別是你作為開發依賴的版本2.2.0
)已經列出了一個舊版本的 vite( vite@"^3.0.0"
)作為它的對等依賴之一,但它是找到更新的vite@"^4.0.4"
安裝。 由於我無法完全解釋的原因(如果您好奇,請參閱鏈接的帖子或谷歌),NPM 無法解決此對等依賴沖突,因為它通常會解決我們更熟悉的常規依賴項和開發依賴項和。 --legacy-peer-deps
通過繞過對等依賴自動安裝來解決這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.