Craco - 无法解决依赖性错误

Hen*_*Lim 14 create-react-app craco

我正在尝试在 Create-React-App 项目中设置 TailwindCSS,并且正在尝试安装 craco,这样我就不需要弹出我的 CRA

当我运行以下命令 npm install @craco/craco 时,我无法解决依赖关系树错误。以下是错误的详细信息。我应该怎么办?谢谢

npm install @craco/craco
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: exchange@0.1.0
npm ERR! Found: react-scripts@3.4.3
npm ERR! node_modules/react-scripts
npm ERR!   react-scripts@"3.4.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react-scripts@"^4.0.0" from @craco/craco@6.1.1
npm ERR! node_modules/@craco/craco
npm ERR!   @craco/craco@"*" 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! 
Run Code Online (Sandbox Code Playgroud)

Anj*_*tam 10

这对我有用

npm install @craco/craco --save --legacy-peer-deps
Run Code Online (Sandbox Code Playgroud)

通过以下行,您还可以--legacy-peer-deps永久设置为配置选项。尽量避免这种情况,因为您需要查看项目中的哪些 npm 库存在依赖性问题。

npm config set legacy-peer-deps true
Run Code Online (Sandbox Code Playgroud)


Hen*_*Lim 5

我已将我的软件包更新react-scripts到最新版本 4.x。通过运行此命令:

npm i react-scripts@latest
Run Code Online (Sandbox Code Playgroud)

然后你瞧,我竟然安装craco成功了。