Next.js 15中初始化shadcn/ui时依赖解析失败求助
问题:Next.js 15 初始化 shadcn/ui 时遭遇依赖冲突错误
我在 Next.js 15 中初始化 shadcn/ui 时遇到了如下依赖错误:
$ npx create-next-app@rc --empty dummy ... $ npx shadcn-ui@latest init √ Which style would you like to use? » Default √ Which color would you like to use as base color? » Slate √ Would you like to use CSS variables for colors? ... no / yes ✔ Writing components.json... ✔ Initializing project... ⠙ Installing dependencies...Command failed with exit code 1: npm install tailwindcss-animate class-variance-authority clsx tailwind-merge lucide-react npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: dummy@0.1.0 npm ERR! Found: react@19.0.0-rc-f994737d14-20240522 npm ERR! node_modules/react npm ERR! react@"19.0.0-rc-f994737d14-20240522" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react@"^16.5.1 || ^17.0.0 || ^18.0.0" from lucide-react@0.379.0 npm ERR! node_modules/lucide-react npm ERR! lucide-react@"*" 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! npm ERR! For a full report see: npm ERR! C:\Users\mjohn\AppData\Local\npm-cache\_logs\2024-05-27T07_23_52_988Z-eresolve-report.txt
请问这是什么原因导致的?
原因分析
这个错误是依赖版本不兼容导致的:
- Next.js 15(RC版本)默认搭载 React 19 的候选版本(
react@19.0.0-rc-f994737d14-20240522)。 - shadcn/ui 初始化时会自动安装
lucide-react@0.379.0,该版本的对等依赖仅声明支持 React 16.5.1、17.x 和 18.x 版本,未包含 React 19 RC 版本。 - npm 的依赖解析机制会严格校验对等依赖的版本匹配,当检测到项目使用的 React 版本不在包声明的支持范围内时,就会抛出
ERESOLVE依赖树解析错误。
简言之:你使用的 React 版本过于超前,当前安装的 lucide-react 尚未适配该版本。
内容的提问来源于stack exchange,提问作者user3357926
相关产品推荐
相关产品推荐

