我想使用react-native cli创建一个新的react-native应用程序,因此我根据https://reactnative.dev/docs/environment-setup文档使用了命令npx react-native init newApp
。在执行此命令时,我得到了如下npm错误日志:
PS D:\Android development> npx react-native init newApp
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
Need to install the following packages:
react-native@0.70.3
Ok to proceed? (y) y
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react-native@0.68.1
npm ERR! node_modules/react-native
npm ERR! peer react-native@"*" from @react-native-community/cli@7.0.3
npm ERR! node_modules/@react-native-community/cli
npm ERR! @react-native-community/cli@"^7.0.3" from react-native@0.68.1
npm ERR! react-native@"0.70.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! react-native@"0.70.3" from the root project
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-native@0.70.3
npm ERR! node_modules/react-native
npm ERR! react-native@"0.70.3" 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! See C:\Users\abhad\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\abhad\AppData\Local\npm-cache\_logs\2022-10-13T07_58_54_900Z-debug-0.log
有谁能解决这个问题吗?请提出一个解决方案。
1条答案
按热度按时间4ktjp1zp1#
我刚刚修复了这个问题。看起来是npm的问题。
我只是在运行
npx react-native init newApp
之前运行了npm config set legacy-peer-deps true
(根据https://github.com/facebook/react-native/issues/34051),这就修复了所有问题!