摘要:
Application AFirstDemo has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerConponent
如图:
运行刚穿件的 RN demo的时候,突然报错说没有注册之类的。刚创建的时候还好好的,突然间就不行了。这个问题经过查找资料终于解决了。这里记录一下,以便回顾、如果能帮到其他人那就更好了。
主要有两种解决方法
- Application AFirstDemo has not been registered。即项目未注册
- 初始化失败、监听本地服务器8081端口失败
如果未注册就仔细检查注册代码并完成注册。
在项目主代码 index.ios.js/index.android.js 最后注册中写入正确的注册名
AppRegistry.registerComponent('AFirstDemo', () => AFirstDemo);可能是新生成的项目运行占用了本地服务器的8081端口,导致原来项目无法监听
查看8081端口是否被占用:切换到项目所在目录,输入react-native start 如果出现Packager can't listen on port 8081那说明端口被占用了。
解决如下
在终端如下操作:
1.lsof -n -i4TCP:8081 列出被占用的端口列表
2.kill -9 <PID> 找到与之对应的PID然后删除即可
3.重新运行项目 react-native run-ios/android
如果还有其他的问题,或者问题的详细原因,欢迎在下面评论中指出,谢谢!