作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
React Native 新手:
我使用 Expo init 开始了一个全新的项目,然后按照 https://reactnavigation.org/docs/hello-react-navigation 中提到的说明进行操作
我使用 expo start 运行项目,但出现此错误。
不变违规:“main”尚未注册。在以下情况下可能会发生这种情况:
AppRegistry.registerComponent
导致模块加载失败没有被调用。 最佳答案
打开index.js
,文件的内容应该是这样的:
import { AppRegistry, Platform } from 'react-native';
import App from './App';
AppRegistry.registerComponent('X', () => App);
if (Platform.OS === 'web') {
const rootTag = document.getElementById('root') || document.getElementById('X');
AppRegistry.runApplication('X', { rootTag });
}
如果您遇到此错误
Invariant Violation: “main” has not been registered
您必须更换
'X'
通过
'main'
.
Invariant Violation: “app” has not been registered
您必须更换
'X'
通过
'app'
.
./android/app/src/main/java/[multiple folders]/MainActivity.java
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "X";
}
'X'
的
MainActivity.java
和
index.js
必须匹配。
关于javascript - 不变违规 : "main" has not been registered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62649381/
我是一名优秀的程序员,十分优秀!