Javascript 调用 AppRegistry.registerComponent 失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35449248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failure to call AppRegistry.registerComponent
提问by vasavi
I created a new project using
react-native init Wevaha
,after that I excute it work's properly then I modified sample app based on my requirement again run it works properly but the next time while running the app I am gettingthe error like' Application Wevaha has not been registered.This is either due to a require() error during intialization or failure to call
AppRegistry.registerComponent'
我使用创建了一个新项目
react-native init Wevaha
,之后我执行它正常工作然后我根据我的要求修改了示例应用程序再次运行它正常工作但下次运行应用程序时我收到错误' Application Wevaha has not been registered.This is either due to a require() error during intialization or failure to call
AppRegistry.registerComponent'
回答by oblador
It is likely that you already have another React Native packager server running for another app or that the app name in AppDelegate.m and your index.js is not the same.
很可能你已经有另一个 React Native 打包服务器为另一个应用程序运行,或者 AppDelegate.m 中的应用程序名称和你的 index.js 不一样。
Try closing all terminal windows, double check the value of moduleName
and run the project again.
尝试关闭所有终端窗口,仔细检查 的值moduleName
并再次运行项目。
回答by jmares93
For us, the problem was that the name of the app registered did not match the root folder. So, if your root folder is /ChatApp
, then register your app as so:
对我们来说,问题是注册的应用程序名称与根文件夹不匹配。因此,如果您的根文件夹是/ChatApp
,请按如下方式注册您的应用:
AppRegistry.registerComponent('ChatApp', () => App);
回答by dwilt
To elaborate on what oblador said, I was still having this issue after closing all the terminal windows/killing all the other React Native processes. What happened to me was the value of the moduleName
in AppDelegate.m
(in the root of the XCode project) was incorrect. I am using a build from Barton Hammond's Snowflakeand was trying to rename it from "snowflake" to my own and I missed this value and was getting that error.
为了详细说明 oblador 所说的内容,在关闭所有终端窗口/杀死所有其他 React Native 进程后,我仍然遇到这个问题。发生在我身上的是moduleName
in AppDelegate.m
(在 XCode 项目的根目录中)的值不正确。我正在使用Barton Hammond 的 Snowflake的构建版本,并试图将其从“snowflake”重命名为我自己的,但我错过了这个值并收到了该错误。
回答by haxpor
For my case, I take a look at packager port number in which it's listening.
It's the result from your calling npm start
at your root project directory.
就我而言,我查看了它正在侦听的打包程序端口号。这是您npm start
在根项目目录中调用的结果。
┌────────────────────────────────────────────────────────────────────────────┐ │ Running packager on port 8081. │ │ │ │ Keep this packager running while developing on any JS projects. Feel │ │ free to close this tab and run your own packager instance if you │ │ prefer. │ │ │ │ https://github.com/facebook/react-native │ │ │ └────────────────────────────────────────────────────────────────────────────┘
Then I check which application is listening on that port via
然后我通过以下方式检查哪个应用程序正在侦听该端口
lsof -i :8081
lsof -i :8081
Result:
结果:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME AwesomePr 8131 haxpor 9u IPv6 0x372bdab8e928e839 0t0 TCP localhost:56484->localhost:sunproxyadmin (SYN_SENT)
Now take that PID
number, and force killing it via
现在取那个PID
号码,并通过以下方式强制杀死它
kill -9 8131
kill -9 8131
Run your packager again ideally with resetting of cache via npm start -- --reset-cache
, it should be fine now.
理想情况下通过重置缓存再次运行您的打包程序npm start -- --reset-cache
,现在应该没问题了。
FYI:
仅供参考:
react: 15.4.2
, react-native: 0.41.2
反应:15.4.2
,反应原生:0.41.2
回答by David Cheung
In my case, it is caused by the case sensitivity of the app name in index.ios.js
.
就我而言,它是由index.ios.js
.
It works after I changed from
我改变后它有效
AppRegistry.registerComponent('AppleReactNative', () => App)
to
到
AppRegistry.registerComponent('applereactnative', () => App)
回答by philip_nunoo
Killing all other node processes worked for me
ie.
ps -ef | grep node
to find those process and
杀死所有其他节点进程对我有用,即。
ps -ef | grep node
找到这些过程和
pkill -f node
pkill -f node
to kill the processes
杀死进程
回答by Satish Mavani
If facing this issue while running on android device or android emulator,
如果在 android 设备或 android 模拟器上运行时遇到此问题,
apart from index.js You should also make sure that app name should be the same in below file index.android.bundle
:
除了 index.js 你还应该确保应用程序名称在下面的文件中应该是相同的index.android.bundle
:
which you can find at this path: ~android/app/src/main/assets/index.android.bundle
您可以在此路径中找到: ~android/app/src/main/assets/index.android.bundle
Search for the old app name and replace it with the actual name.
搜索旧的应用程序名称并将其替换为实际名称。
it worked for me, hope it helps others too.
它对我有用,希望它也能帮助其他人。
回答by Saad Abdeen
just remove the small bracket from ((appName, () => App));
只需从 ((appName, () => App)) 中删除小括号;
AppRegistry.registerComponent(appName, () => App);