【问题标题】:npm chakra-ui install failing due to dependency conflicts由于依赖冲突,npm chakra-ui 安装失败
【发布时间】:2020-11-24 22:44:11
【问题描述】:

我正在尝试学习 react/typescript,并且我正在逐行遵循教程,但在尝试安装 @chakra-ui/react 或 @chakra-ui/core 时不知何故出现此错误。似乎反应已更新的依赖问题。我应该回滚反应吗?

kyoudai.industries git:(master) ✗ npm install @chakra-ui/react framer-motion
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: kyoudai.industries@1.0.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR!   peer react@"16.x || 17.x" from @chakra-ui/react@1.0.1
npm ERR!   node_modules/@chakra-ui/react
npm ERR!     @chakra-ui/react@"*" from the root project
npm ERR!   2 more (@emotion/react, @emotion/styled)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8" from framer-motion@2.9.4
npm ERR! node_modules/framer-motion
npm ERR!   framer-motion@"*" from the root project
npm ERR!   peer framer-motion@"^2.9.4" from @chakra-ui/react@1.0.1
npm ERR!   node_modules/@chakra-ui/react
npm ERR!     @chakra-ui/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! See /Users/travis/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/travis/.npm/_logs/2020-11-24T22_38_57_297Z-debug.log

【问题讨论】:

    标签: node.js reactjs npm chakracore chakra-ui


    【解决方案1】:

    使用这个命令可以解决问题:

    npm i @chakra-ui/react --legacy-peer-deps

    【讨论】:

    • 您能解释一下为什么该解决方案有效以及问题中使用的实现有什么问题吗?
    • 我认为因为 chakra-ui 没有更新 peerDependencies 并且它与 react v17 冲突,您可以在安装时使用 --legacy-peer-deps 标志。随着项目逐渐更新其冲突的依赖关系,npm v7 启用了此标志一段时间。
    【解决方案2】:

    我遇到了同样的问题,但在 Vue.js 中。我运行了以下命令,它开始工作了:

    vue create test -p default && cd test && vue serve src/main.js,
    

    它似乎创建了一个运行一些测试的文件夹。

    然后我跑了:npm i -g @vue/cli-service-global.

    然后:npm run serve-- 启动 vue 服务器。

    希望它能让你了解如何在 React 中解决这个问题。 祝你好运!

    【讨论】:

    • 这应该是comment 而不是答案。
    猜你喜欢
    • 2023-02-06
    • 2021-10-14
    • 2023-02-12
    • 2017-06-26
    • 2011-11-20
    • 1970-01-01
    • 2021-06-21
    • 2021-12-14
    • 1970-01-01
    相关资源
    最近更新 更多