大家好,今天我遇到了一个问题,当我使用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但没有任何结果
P粉0432953372023-11-11 17:02:39
您应该能够使用以下命令解决此错误:
npm install --legacy-peer-deps
这个上一篇文章详细介绍了 --legacy-peer-deps
在这里所做的事情。
简而言之,@vitejs/plugin-react
(特别是您作为开发依赖项的版本 2.2.0
)列出了旧版本的 vite(vite@"^3.0.0"
) 作为其对等依赖项之一,但它正在查找已安装的较新的 vite@"^4.0.4"
。由于我无法完全解释的原因(如果您好奇,请参阅链接的帖子或 Google),NPM 无法解决这种对等依赖冲突,就像我们更熟悉的常规依赖项和开发依赖项通常会解决的那样和。 --legacy-peer-deps
通过绕过对等依赖项自动安装来解决此问题。