Material UI Icons npm 安装问题:无法解析依赖树

2024-05-04

---------问题已解决 - 问题末尾的解决方案--------

我试图安装材质 UI 图标 https://mui.com/components/material-icons/在我使用 npm 的 Netflix-Clone React.js 项目中,但出现以下错误 -

PS D:\REACT Projects\netflix> npm i @mui/icons-material @mui/material
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected] /cdn-cgi/l/email-protection
npm ERR! Found: [email protected] /cdn-cgi/l/email-protection
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0" from the root project
npm ERR!   peer react@">=16.8.0" from @emotion/[email protected] /cdn-cgi/l/email-protection
npm ERR!   node_modules/@emotion/react
npm ERR!     peerOptional @emotion/react@"^11.5.0" from @mui/[email protected] /cdn-cgi/l/email-protection
npm ERR!     node_modules/@mui/material
npm ERR!       @mui/material@"^5.5.3" from the root project
npm ERR!       1 more (@mui/icons-material)
npm ERR!     peer @emotion/react@"^11.0.0-rc.0" from @emotion/[email protected] /cdn-cgi/l/email-protection
npm ERR!     node_modules/@emotion/styled
npm ERR!       peerOptional @emotion/styled@"^11.3.0" from @mui/[email protected] /cdn-cgi/l/email-protection
npm ERR!       node_modules/@mui/material
npm ERR!         @mui/material@"^5.5.3" from the root project
npm ERR!         1 more (@mui/icons-material)
npm ERR!   1 more (@emotion/styled)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from @mui/[email protected] /cdn-cgi/l/email-protection
npm ERR! node_modules/@mui/material
npm ERR!   @mui/material@"^5.5.3" from the root project
npm ERR!   peer @mui/material@"^5.0.0" from @mui/[email protected] /cdn-cgi/l/email-protection
npm ERR!   node_modules/@mui/icons-material
npm ERR!     @mui/icons-material@"^5.5.1" 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.

下面是我的package.json file -

{
  "name": "netflix",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@mui/icons-material": "^5.5.1",
    "@mui/material": "^5.5.3",
    "@testing-library/jest-dom": "^5.16.3",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^14.0.4",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-scripts": "5.0.0",
    "sass": "^1.49.10",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I saw a stackoverflow 上有类似问题的帖子 https://stackoverflow.com/questions/70587214/eresolve-unable-to-resolve-dependency-tree-for-mui-material,并尝试实施那里提到的解决方案,但没有成功。

  1. 首先,我重试了这个命令--force - npm i @mui/icons-material @mui/material --force

这使我能够安装 MUI 图标包而不会出现任何错误,但是,当我尝试在项目中使用这些图标时,我遇到了许多错误。

  1. 接下来,我改变了react and react-dom版本到 16.8.0package.json文件,然后点击npm install。然而,这次我也遇到了以下错误 -
PS D:\REACT Projects\netflix> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected] /cdn-cgi/l/email-protection
npm ERR! Found: [email protected] /cdn-cgi/l/email-protection
npm ERR! node_modules/react
npm ERR!   react@"^16.8.0" from the root project
npm ERR!   peer react@">=16.8.0" from @emotion/[email protected] /cdn-cgi/l/email-protection
npm ERR!   node_modules/@emotion/react
npm ERR!     peerOptional @emotion/react@"^11.5.0" from @mui/[email protected] /cdn-cgi/l/email-protection
npm ERR!     node_modules/@mui/material
npm ERR!       @mui/material@"^5.5.3" from the root project
npm ERR!       1 more (@mui/icons-material)
npm ERR!     peer @emotion/react@"^11.0.0-rc.0" from @emotion/[email protected] /cdn-cgi/l/email-protection
npm ERR!     node_modules/@emotion/styled
npm ERR!       peerOptional @emotion/styled@"^11.3.0" from @mui/[email protected] /cdn-cgi/l/email-protection
npm ERR!       node_modules/@mui/material
npm ERR!         @mui/material@"^5.5.3" from the root project
npm ERR!         1 more (@mui/icons-material)
npm ERR!   1 more (@emotion/styled)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from @mui/[email protected] /cdn-cgi/l/email-protection
npm ERR! node_modules/@mui/material
npm ERR!   @mui/material@"^5.5.3" from the root project
npm ERR!   peer @mui/material@"^5.0.0" from @mui/[email protected] /cdn-cgi/l/email-protection
npm ERR!   node_modules/@mui/icons-material
npm ERR!     @mui/icons-material@"^5.5.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry

老实说我现在不知道该怎么办。我认为互联网上会有更好的解决方案,但我到处都看到相同的答案,要么使用 --force/--legacy-peer-deps 要么降级我的react/react-dom版本。如上所述,这些选项都不起作用。 对此有更好的解决方案吗?老实说,我很惊讶这样一个众所周知的软件包在安装时会出现这么多问题。

编辑 - 问题已解决
感谢@ckesplin的帮助,终于成功了。我按照以下步骤操作 -

  1. 执行npx create-react-app netflix.
  2. Changed react and react-dom版本为17.0.0从 18.0.0 开始。
  3. Deleted package-lock.json文件和node_modules文件夹。 然后打npm install.
  4. 执行npm i @mui/icons-material @mui/material...安装成功。
  5. 然而,在使用图标时,我再次遇到了一堆错误找不到模块:无法解析@emotion/styled。所以我不得不npm i @emotion/react @emotion/styled

从日志中可以看出@mui/[email protected] /cdn-cgi/l/email-protection需要react@"^17.0.0"。 (您尝试同时响应 18.0.0 和 16.14.0,但不响应 ^17.0.0)

将以下内容替换为您的package.json并给它 ol'npm install

 "dependencies": {
    ...
    "react": "^17.0.0",
    "react-dom": "^17.0.0",
    ...
  },
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Material UI Icons npm 安装问题:无法解析依赖树 的相关文章

  • onClick 处理程序在每个渲染周期触发

    我有这样的默认状态 this state selectedTab tab1 then 我的渲染方法是这样的 render const selectedTab this state return li tab1 li li tab2 li d
  • 在反应中访问回调内的 event.target

    我有以下课程片段 constructor props super props this timeout null search e gt clearTimeout this timeout this timeout setTimeout f
  • 如何通过 React-router-4 删除所有浏览器历史记录

    我在用react router在水疗中心 就我而言 浏览器历史记录是 home gt somepage1 gt another gt changepassword 当我在路线上做某事时 changepassword 我想去 login路线
  • 如何让 webpack 转换 React 生产文件?

    当我使用 webpack 与 React 16 捆绑我的应用程序时 我在浏览器中收到 Uncaught ReferenceError require is not Defined 对于react和react dom 导致错误的资源是reac
  • 如何使用 API 中的数据填充选择的下拉元素 - ReactJS

    我对 React 还很陌生 我正在从 API 获取数据 当我检查控制台日志时可以看到数据 但是我不知道如何使用 map 创建一个新数组 然后选项元素可以使用该数组来显示货币代码 目前它填充下拉列表 但选项元素全部为空 结果显示为 NaN 下
  • 如何在react.js中将/n替换为换行符?

    我正在尝试更换每一个 n to a br tag in ReactJS In my note note对象有一个包含多个的字符串 n in it 示例注释 注释 test ntest ntest 我尝试过的ReactJS note note
  • 需要 Java 源文件的依赖树

    我需要从大型遗留 Java 代码库中提取一些特定功能 以便将其转换为独立的命令行应用程序 这段代码根本没有文档记录 并且不是很模块化 甚至不是很清晰 所以我很难弄清楚我需要保留什么 基本上我需要的是一棵依赖关系树 列出了这个 java 文件
  • React-Redux:操作必须是普通对象。使用自定义中间件进行异步操作

    未处理的拒绝 错误 操作必须是普通对象 使用自定义中间件进行异步操作 我想为每个帖子添加评论 因此 当运行获取帖子时 我想为所有帖子调用获取评论 API export function bindComments postId return
  • 在AWS S3中部署react-redux应用程序

    我在堆栈溢出中遇到了很多类似的问题one https stackoverflow com questions 16267339 s3 static website hosting route all paths to index html
  • 使用 stopPropagation() 处理 React 事件委托

    我有一个 React 项目 应该可以放置在任何网站上 我的想法是 我托管一个 javascript 文件 人们放置一个具有特定 ID 的 div 然后 React 在该 div 中进行渲染 到目前为止 除了点击事件之外 这是有效的 这些事件
  • CORS 问题从 React 应用程序 > 节点服务器 > 重定向到 Google OAuth2 身份验证发出 AJAX 请求

    大家好 过去两天我一直在绞尽脑汁研究这个问题 但没有运气 这是我在尝试从我的 React 应用程序 localhost 3000 使用 Google Oauth2 Passport 策略进行身份验证时遇到的错误 我正在 localhost
  • 我想将我的 NEXT.js 项目链接到静态网站

    我有一个使用 HTML CSS 开发的网站 它是一个静态网站 但现在我使用 NEXT js 与 Strapi API 集成创建了一个博客项目 我的问题是如何将我的静态网站与我的 Next js 项目链接起来 我尝试使用链接标签 但没有用 i
  • 无法在scrollView中滚动

    我有一个屏幕 我可以在输入字段中输入内容并获得相应的搜索结果 该列表在 ScrollView 中呈现 但当键盘打开时 在 Android 中 它仍然不允许我滚动 我怎样才能解决这个问题 return lt gt addressesFound
  • NPM:切勿为 npm 包安装嵌套的可选依赖项

    我正在编写一个包 A 我想将其发布到 NPM A 依赖于包 B 而包 B 又依赖于包 C 然后 C 有两个可选的本机依赖项 D 和 E 我明确知道我没有使用可选依赖项 D 和 E 并且永远不想当有人安装我的软件包时尝试安装它们 我知道你可以
  • Azure无法访问React Web应用程序中的env变量

    几年前我看到有一个类似的问题 但超链接答案已被微软关闭 我有一个使用 create react app 创建的 React 应用程序 它已经部署到heroku并加载一些环境变量来访问谷歌地图等 这一切对于heroku来说都工作得很好 我已经
  • GraphQL - POST 正文丢失。您忘记使用 body-parser 中间件了吗?

    我的电脑上不断出现以下错误graphql查询但不确定原因 POST body missing Did you forget use body parser middleware 我在这里做了什么奇怪的事吗 我已经尝试了在线 body par
  • 在 createAsyncThunk 上调度操作?

    我有一个 thunk 动作是由createAsyncThunk 我想在调用 api 更新状态之前调度一个操作 我不想使用动作getProducts pending因为我想要派遣actionLoading 对于其他 thunk 操作 我怎样才
  • React TypeError:x 不是函数

    我在子组件中从父组件调用函数 booksRefresh 但出现错误 类型错误 booksRefresh 不是函数 我不知道为什么 因为 booksRefresh 是一个函数 有人可以帮我解释为什么会出现这个错误吗 这是我的代码 import
  • 使用样式组件更改 SVG 描边的颜色

    我有一个 SVG 用作 img 标签 使用样式组件 我试图达到在悬停时更改描边颜色的程度 我导入了 SVG import BurgerOpenSvg from images burger open svg 我为它创建了一个样式组件 cons
  • 如何为React hooks(useState等)做流类型注解?

    我们应该如何将 Flow 类型注释与 React hooks 一起使用 例如useState 我尝试寻找一些如何实施它们的示例 但找不到任何东西 我试过这个 const allResultsVisible setAllResultsVisi

随机推荐