Application MyTest has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.

运行react-native项目时报错。

说明一下:项目本来是好的,再次运行就报错了

解决解决办法倒是有,不过具体什么原因不知道。希望有知道具体原因的童鞋能够补充一下

第一种情况:真的是注册的时候写错了。也就是这段话注册的不对:

AppRegistry.registerComponent('MyDemo', () => MyDemo);

注意:‘MyDemo’这个是项目名 MyDemo这个你可以随自己你喜好指定。

第二种情况:也就是其他情况,你感觉什么都是好的但是运行起来还是会报这个错误。那么很有可能是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

打完收工

原文地址:https://www.cnblogs.com/tony-yang-flutter/p/5880227.html