简体   繁体   English

启动新的 React Native 项目时出错

[英]Error when starting new React Native Project

I'm following the setup instructions from the React Native Documentation page, on my M1 Macbook Pro.我在 M1 Macbook Pro 上按照 React Native文档页面中的设置说明进行操作。 I have previously worked on React projects and was able to create and run React Native Expo projects previously on the same machine.我之前从事过 React 项目,并且能够在同一台机器上创建和运行 React Native Expo 项目。

I followed the instructions to the letter, but when I arrived at the ' Create A New Application " section, using the npx react-native init AwesomeProject command, the new project creation failed. Here are the error message outputted on the Terminal:我按照信中的说明进行操作,但是当我到达“ 创建新应用程序”部分时,使用npx react-native init AwesomeProject命令,新项目创建失败。以下是终端上输出的错误消息:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react-native@0.66.4
npm ERR! node_modules/react-native
npm ERR!   peer react-native@"*" from @react-native-community/cli@6.3.1
npm ERR!   node_modules/@react-native-community/cli
npm ERR!     @react-native-community/cli@"^6.0.0" from react-native@0.66.4
npm ERR!   react-native@"0.69.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! react-native@"0.69.2" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@18.0.0
npm ERR! node_modules/react
npm ERR!   peer react@"18.0.0" from react-native@0.69.2
npm ERR!   node_modules/react-native
npm ERR!     react-native@"0.69.2" 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.

I tried to uninstall react-native and install it back but couldn't find a proper instruction on the net to do that.我试图卸载 react-native 并将其重新安装,但在网上找不到正确的说明来执行此操作。 How can I just scrape the previously installed react-native (judging from the error message, i got RN@0.66.4, when I want to use the latest RN) and install a fresh, latest react native?我怎样才能刮掉以前安装的 react-native (从错误消息来看,当我想使用最新的 RN 时,我得到了 RN@0.66.4)并安装一个全新的、最新的 react native?

if you are on Mac and your node version is 18. .如果你在 Mac 上并且你的节点版本是 18 .. which Is latest but not greatest.. you need to download 16. .这是最新但不是最好的..你需要下载16 .. the stable one.稳定的。

Step-1步骤1

brew uninstall node; 
# or `brew uninstall --force node` which removes all versions
brew cleanup;
rm -f /usr/local/bin/npm /usr/local/lib/dtrace/node.d;
rm -rf ~/.npm;

Step 2 - and install it from node site by downloading the binary第 2 步 - 通过下载二进制文件从节点站点安装它

Step 3 - just check the node version again if you have 16. .第 3 步 - 如果您有 16 个,只需再次检查节点版本 then you can try creating the react native project once again.然后你可以尝试再次创建 react native 项目。 Please let us know if it worked for you.请让我们知道它是否对您有用。 Wish you luck!!祝您好运!!

In addition to what the answer suggests, you can do brew install node@16 to install this particular version instead of manually downloading the binary.除了答案建议的内容外,您还可以执行brew install node@16来安装此特定版本,而不是手动下载二进制文件。

If installing node version 16 doesn't work for you ensure you update npm by running sudo npm update -g .如果安装节点版本 16 对您不起作用,请确保通过运行sudo npm update -g更新 npm。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM