Failed to install react-native-web@~0.18.7, react-dom with error: npm exited with non-zero code: 1 npm exited with non-zero code: 1

huangapple go评论61阅读模式
英文:

Failed to install react-native-web@~0.18.7, react-dom with error: npm exited with non-zero code: 1 npm exited with non-zero code: 1

问题

我正在尝试在Web上启动一个Expo项目,但出现了这个错误,有人可以帮助我吗?

按下a │ 打开Android
› 按下w │ 打开Web

› 按下r │ 重新加载应用
› 按下m │ 切换菜单

› 按下? │ 显示所有命令

您的项目的日志将显示在下方。按Ctrl+C退出。
启动Metro捆绑器
√ 看起来您正在尝试使用Web支持,但未安装所需的依赖项。是否要安装
react-native-web, react-dom? ... 是

× 安装react-native-web@〜0.18.7、react-dom失败,出现错误:npm退出,退出代码为:1
npm退出,退出代码为:1

› 停止服务器
C:\Users\Human\News-Application>expo start

此命令正在使用全局Expo CLI执行。了解更多信息:https://blog.expo.dev/the-new-expo-cli-f4250d8e3421
要改用本地CLI(在SDK 46及更高版本中推荐),请运行:
› npx expo start

在C:\Users\Human\News-Application启动项目
"react-native-web"已添加为项目的package.json的依赖项,但似乎尚未安装。请运行"yarn"或"npm install"来解决此问题。

C:\Users\Human\News-Application>npm install react-native-web
npm警告 配置全局--global, --local已弃用。请改用--location=global
npm错误! 代码ERESOLVE
npm错误! ERESOLVE 无法解析依赖树
npm错误!
npm错误! 在解析:news-application@1.0.0时
npm错误! 找到:react@18.1.0
npm错误! node_modules/react
npm错误! react@"18.1.0" 来自根项目
npm错误! 从react-native-web@0.18.12找到peer react@"^17.0.2 || ^18.0.0"
npm错误! node_modules/react-native-web
npm错误! react-native-web@"~0.18.7" 来自根项目
npm错误!
npm错误! 无法解决依赖关系:
npm错误! 从react-dom@18.2.0找到peer react@"^18.2.0"
npm错误! node_modules/react-dom
npm错误! 从react-native-web@0.18.12找到peer react-dom@"^17.0.2 || ^18.0.0"
npm错误! node_modules/react-native-web
npm错误! react-native-web@"~0.18.7" 来自根项目
npm错误!
npm错误! 修复上游依赖冲突,或使用--force或--legacy-peer-deps重试
npm错误! 接受不正确(可能损坏)的依赖关系解析。
npm错误!
npm错误!
npm错误! 有关完整报告,请参见:
npm错误! C:\Users\Human\AppData\Local\npm-cache_logs\2023-02-10T03_04_04_748Z-eresolve-report.txt

npm错误! 此运行的完整日志可在以下位置找到:
npm错误! C:\Users\Human\AppData\Local\npm-cache_logs\2023-02-10T03_04_04_748Z-debug-0.log

我尝试使用npm install安装react-native-web,我预期会顺利安装,但它显示安装react-native-web@~0.18.7失败,出现错误:npm退出,退出代码为:1。

英文:

I am trying to start a expo project on web but it throws this error, Can anyone help me please?

Press a │ open Android
› Press w │ open web

› Press r │ reload app
› Press m │ toggle menu

› Press ? │ show all commands

Logs for your project will appear below. Press Ctrl+C to exit.
Started Metro Bundler
√ It looks like you're trying to use web support but don't have the required dependencies installed. Would you like to install
react-native-web, react-dom? ... yes

× Failed to install react-native-web@~0.18.7, react-dom with error: npm exited with non-zero code: 1
npm exited with non-zero code: 1
?
› Stopped server
C:\Users\Human\News-Application>expo start

This command is being executed with the global Expo CLI. Learn more: https://blog.expo.dev/the-new-expo-cli-f4250d8e3421
To use the local CLI instead (recommended in SDK 46 and higher), run:
› npx expo start

Starting project at C:\Users\Human\News-Application
"react-native-web" is added as a dependency in your project's package.json but it doesn't seem to be installed. Please run "yarn" or "npm install" to fix this issue.

C:\Users\Human\News-Application>npm install react-native-web
npm WARN config global --global, --local are deprecated. Use --location=global instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: news-application@1.0.0
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR! react@"18.1.0" from the root project
npm ERR! peer react@"^17.0.2 || ^18.0.0" from react-native-web@0.18.12
npm ERR! node_modules/react-native-web
npm ERR! react-native-web@"~0.18.7" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.2.0" from react-dom@18.2.0
npm ERR! node_modules/react-dom
npm ERR! peer react-dom@"^17.0.2 || ^18.0.0" from react-native-web@0.18.12
npm ERR! node_modules/react-native-web
npm ERR! react-native-web@"~0.18.7" 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!
npm ERR! For a full report see:
npm ERR! C:\Users\Human\AppData\Local\npm-cache_logs\2023-02-10T03_04_04_748Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Human\AppData\Local\npm-cache_logs\2023-02-10T03_04_04_748Z-debug-0.log

I tried insalling react-native-web with npm install and I was expecting smooth installation but it says Failed to install react-native-web@~0.18.7 with error: npm exited with non-zero code: 1

答案1

得分: 1

我通过按照控制台消息的建议执行强制安装,然后使用 expo doctor(同样是根据控制台消息的建议)来修复依赖关系问题解决了这个问题。

npm install react-native-web, react-dom --force

安装完成后,执行以下命令:

expo doctor --fix-dependencies

之后我的应用成功运行。

英文:

I resolved this issue by doing a force install as the console messages were suggesting and then using expo doctor (again as the console messages were suggestion) to fix the dependency issue.

npm install react-native-web, react-dom --force

and once the installation is done, do:

expo doctor --fix-dependencies

My app runs successfully afterwards.

huangapple
  • 本文由 发表于 2023年2月10日 11:27:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定