logo头像
Snippet 博客主题

RN入门

环境配置

转载博客地址

初始化项目

react-native init 项目名
##报错

报错一

参照博客

1
2
3
error react-native@0.57.1: The engine "node" is incompatible with this module. Expected version ">=8.3". Got "6.10.2"
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

解决:
更新node

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
### 第一步:使用npm安装n模块

* * *

n模块是专门用来管理nodejs版本的

sudo npm install -g n

> **提示 :** 如果不使用sudo作为前缀,很可能出现权限访问异常导致安装失败

### 第二步:升级nodejs

* * *

升级nodejs是有两种方法:
第一种是升级到最新版本

sudo n latest

第二种是升级到稳定版本

sudo n stable

> **提示 :** 建议是稳定版本
> 更多n模块管理请搜索【nodejs n模块使用说明】

报错二

1
error: bundling failed: Error: Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from `/Users/pro/Desktop/RN学习/RNTestDemo/index.js`: Module `@babel/runtime/helpers/interopRequireDefault` does not exist in the Haste module map

解决

1
2
3
npm add @babel/runtime
安装继续没有成功继续报错
npm cache clean --force //清理npm缓存重新安装就可以了

配置成功

至此成功

启动服务器

  • cd到当前项目文件夹下
  • react-native run-ios 启动服务器
  • 第一次运行安装比较耗时
    运行成功
    • 但是又出现新的错误
      运行成功

报错三

在ios下运行出现以下问题

1
RN编译错误之——Print: Entry, ":CFBundleIdentifier", Does Not Exist

解决:

1
2
在网上看了很多都是重新安装node_modules,试过了没有用,这个问题应该是react-native版本的问题,我执行了
react-native upgrade 这个命令就运行成功了
微信打赏

赞赏是不耍流氓的鼓励