【发布时间】:2017-02-17 20:26:53
【问题描述】:
实际上,我要做的只是将初始化代码从index.android.js / index.ios.js 移至app/index.js 文件。我将其导出并将其导入回index.android.js 或index.ios.js。
然后我得到错误。
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
我使用 npm 时没有这个问题。似乎 yarn 的构建过程可能会有所不同,因为每当我在打包程序中保存任何内容时,它都会显示
Bundling 'index.android.js' 但与 iOS 无关。
我的app/index.js 看起来像这样
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
export default class Snapp extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
);
}
}
我的index.android.js 和index.ios.js 文件看起来像这样
import Snapp from './app'
import { AppRegistry } from 'react-native';
AppRegistry.registerComponent('Snapp', () => Snapp);
有什么想法吗?
【问题讨论】:
-
您在安装纱线之间是否使用
react native start -- --reset-cache重新启动了打包程序? -
我在我的项目中运行了
rm yarn.lock && rm -rf node_module && npm install,也运行了react-native start --reset-cache,但仍然出现错误。 -
确保打包程序已关闭,也可以尝试
rm -rf ios/build ios/DerivedData rm -rf node_modules。打开 Xcode 项目并清理(cmd + shift + K)。重新安装模块,使用重置缓存重新启动打包程序,然后运行。 -
我也试试,但有没有办法卸载纱线?我环顾四周,但什么都看到了。
-
也会参考有关您如何安装它的文档。
标签: javascript react-native yarnpkg