npm ERR!使用'npx react-native init'时无法解析错误

yuvru6vn  于 2022-11-14  发布在  React
关注(0)|答案(1)|浏览(253)

我想使用react-native cli创建一个新的react-native应用程序,因此我根据https://reactnative.dev/docs/environment-setup文档使用了命令npx react-native init newApp。在执行此命令时,我得到了如下npm错误日志:

  1. PS D:\Android development> npx react-native init newApp
  2. npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
  3. Need to install the following packages:
  4. react-native@0.70.3
  5. Ok to proceed? (y) y
  6. npm ERR! code ERESOLVE
  7. npm ERR! ERESOLVE could not resolve
  8. npm ERR!
  9. npm ERR! While resolving: undefined@undefined
  10. npm ERR! Found: react-native@0.68.1
  11. npm ERR! node_modules/react-native
  12. npm ERR! peer react-native@"*" from @react-native-community/cli@7.0.3
  13. npm ERR! node_modules/@react-native-community/cli
  14. npm ERR! @react-native-community/cli@"^7.0.3" from react-native@0.68.1
  15. npm ERR! react-native@"0.70.3" from the root project
  16. npm ERR!
  17. npm ERR! Could not resolve dependency:
  18. npm ERR! react-native@"0.70.3" from the root project
  19. npm ERR!
  20. npm ERR! Conflicting peer dependency: react@18.1.0
  21. npm ERR! node_modules/react
  22. npm ERR! peer react@"18.1.0" from react-native@0.70.3
  23. npm ERR! node_modules/react-native
  24. npm ERR! react-native@"0.70.3" from the root project
  25. npm ERR!
  26. npm ERR! Fix the upstream dependency conflict, or retry
  27. npm ERR! this command with --force, or --legacy-peer-deps
  28. npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
  29. npm ERR!
  30. npm ERR! See C:\Users\abhad\AppData\Local\npm-cache\eresolve-report.txt for a full report.
  31. npm ERR! A complete log of this run can be found in:
  32. npm ERR! C:\Users\abhad\AppData\Local\npm-cache\_logs\2022-10-13T07_58_54_900Z-debug-0.log

有谁能解决这个问题吗?请提出一个解决方案。

4ktjp1zp

4ktjp1zp1#

我刚刚修复了这个问题。看起来是npm的问题。
我只是在运行npx react-native init newApp之前运行了npm config set legacy-peer-deps true(根据https://github.com/facebook/react-native/issues/34051),这就修复了所有问题!

相关问题