最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

为什么 NPM 不能安装样式组件?如果我使用 Yarn 安装,为什么 Xcode 构建会失败?

网站源码admin35浏览0评论

为什么 NPM 不能安装样式组件?如果我使用 Yarn 安装,为什么 Xcode 构建会失败?

为什么 NPM 不能安装样式组件?如果我使用 Yarn 安装,为什么 Xcode 构建会失败?

我正在尝试使用 React Native CLI 启动 React 应用程序(也尝试使用 Expo,分别使用 Yarn 启动和 NPM 启动)。

这是 NPM 尝试使用 npm 安装样式化组件时出现的错误(见下文)我已尝试完成互联网必须提供的所有修复,例如:

  • 删除节点模块和各种清理
  • 安装新鲜
  • 制作一个全新的项目
  • 更新或重新安装诸如 Node 之类的东西
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"17.0.2" from the root project
npm ERR!   peer react@">=16.0" from @react-native-community/[email protected]
npm ERR!   node_modules/@react-native-community/masked-view
npm ERR!     @react-native-community/masked-view@"^0.1.11" from the root project
npm ERR!   18 more (@react-native-masked-view/masked-view, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react-dom@">= 16.8.0" from [email protected]
npm ERR! node_modules/styled-components
npm ERR!   styled-components@"^5.3.5" from the root project
npm ERR!   peer styled-components@">= 2" from [email protected]
npm ERR!   node_modules/babel-plugin-styled-components
npm ERR!     babel-plugin-styled-components@">= 1.12.0" from [email protected]
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/react
npm ERR!   peer react@"^18.1.0" from [email protected]
npm ERR!   node_modules/react-dom
npm ERR!     peer react-dom@">= 16.8.0" from [email protected]
npm ERR!     node_modules/styled-components
npm ERR!       styled-components@"^5.3.5" from the root project
npm ERR!       1 more (babel-plugin-styled-components)
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/nate/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/nate/.npm/_logs/2022-05-02T16_36_05_349Z-debug-0.log

所以即使我改用 Yarn,它仍然每次都会使我的 Xcode 构建失败(没有样式组件根本没有问题)它就像它破坏了我的构建一样,请参见下面的错误示例。

我试过这样的事情:

  • 清理缓存
  • 重新安装吊舱
  • 节点模块删除并重新安装
 Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
回答如下:

我在一个现有的 React Native 项目上也遇到了和你一样的问题,但是在一个新的项目上没有出现同样的错误。

仔细寻找差异,我发现我现有的 RN 项目没有安装

react-dom
,只有
[email protected]
.

所以,我已经安装了

react-dom
npm install [email protected]
现在我可以安装 Styled Components 而不会出现这个对等依赖错误。

之所以会这样,是因为

styled-components
使用了
"react-dom": ">= 16.8.0"
作为peerDependency,而它本身有
react@"^18.1.0"
作为peerDependency,所以它尝试安装
react@18
而我们的项目使用的是
react@17
,导致这个错误在依赖树上。

所以,当我们在我们的项目上手动安装

react-dom@17
时,它满足了
styled-components
peerDependency 并且还使用了
react@17
,它已经在我们的项目上了

希望有帮助

发布评论

评论列表(0)

  1. 暂无评论