NodeJS 为什么NPM不能用于安装样式化组件?为什么使用Yarn安装Xcode会失败?

q5iwbnjs  于 2023-05-17  发布在  Node.js
关注(0)|答案(3)|浏览(205)

我正在尝试使用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: styled-components@5.3.5
npm ERR! Found: react@17.0.2
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/masked-view@0.1.11
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 styled-components@5.3.5
npm ERR! node_modules/styled-components
npm ERR!   styled-components@"^5.3.5" from the root project
npm ERR!   peer styled-components@">= 2" from babel-plugin-styled-components@2.0.7
npm ERR!   node_modules/babel-plugin-styled-components
npm ERR!     babel-plugin-styled-components@">= 1.12.0" from styled-components@5.3.5
npm ERR! 
npm ERR! Conflicting peer dependency: react@18.1.0
npm ERR! node_modules/react
npm ERR!   peer react@"^18.1.0" from react-dom@18.1.0
npm ERR!   node_modules/react-dom
npm ERR!     peer react-dom@">= 16.8.0" from styled-components@5.3.5
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构建(没有样式化组件,根本没有问题),就像它在某种程度上破坏了我的构建,请参阅下面的错误示例。
我试过这样的方法:

  • 清除缓存
  • 重新安装pod
  • 节点模块删除并重新安装
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.
elcex8rz

elcex8rz1#

我在一个现有的React Native项目上也遇到了同样的问题,但在一个新的项目上没有发生同样的错误。
仔细查看差异,我发现我现有的RN项目没有安装react-dom,只有react@17.0.2
所以,我已经安装了react-domnpm install react-dom@17.0.2,现在我可以安装样式化组件,而不会出现这种对等依赖错误。
发生这种情况的原因是因为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,它已经在我们的项目上。
希望能帮上忙

wtlkbnrh

wtlkbnrh2#

检查它,如果你是从本机文件夹内导入样式组件。

import styled from 'styled-components/native'

并确保所有依赖项都是最新的。
链接到VS Code扩展以查看您的依赖项是否需要升级:https://marketplace.visualstudio.com/items?itemName=codeandstuff.package-json-upgrade

oprakyz7

oprakyz73#

问题:

npm ERR! Cannot read properties of null (reading 'edgesOut')

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\bhara\AppData\Local\npm-cache\_logs\2023-05-14T14_02_09_938Z-debug-0.log
PS C:\Users\bhara\Desktop\Grogu\rasoi> npm install styled-components@6
npm ERR! code ETARGET
npm ERR! notarget No matching version found for styled-components@6.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\bhara\AppData\Local\npm-cache\_logs\2023-05-14T14_03_31_853Z-debug-0.log
PS C:\Users\bhara\Desktop\Grogu\rasoi> npm install styled-components@6
npm ERR! code ETARGET
npm ERR! notarget No matching version found for styled-components@6.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:

对我有效的解决方案:

npm install styled-components@5

相关问题