大家好,今天我遇到了一個問題,當我使用react安裝laravel ui並傳遞到npm install步驟時發生了錯誤,所以下面你會發現錯誤
npm ERR! A complete log of this run can be found in: npm ERR! C:UsersE495AppDataLocalnpm-cache_logs2023-01-16T08_08_36_872Z-debug-0.log PS C:UsersE495Desktoplaravel-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:UsersE495AppDataLocalnpm-cacheeresolve-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但沒有任何結果
您應該能夠使用以下命令解決此錯誤:
這個上一篇文章詳細介紹了
--legacy-peer-deps
在這裡所做的事情。簡而言之,
@vitejs/plugin-react
(特別是您作為開發依賴項的版本2.2.0
)列出了舊版本的vite(vite@"^3.0.0"
) 作為其對等依賴項之一,但它正在尋找已安裝的較新的vite@"^4.0.4"
。由於我無法完全解釋的原因(如果您好奇,請參閱連結的帖子或Google),NPM 無法解決這種對等依賴衝突,就像我們更熟悉的常規依賴項和開發依賴項通常會解決的那樣和。--legacy-peer-deps
透過繞過對等依賴項自動安裝來解決此問題。