我刚刚添加
var React = require('react-native');
到我的index.ios.js文件,但是当我重新加载我的React Native应用程序时,这个 出现:
所以我尝试通过以下方式更改react-native模块的权限
sudo chmod -R 777 ExampleProject
sudo chmod -R 777 ExampleProject/node_modules/react-native
但是还是不行。我做错了什么?
这是我的index.ios.js 文件的完整源代码:
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View
} from 'react-native';
class Logbook extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('Logbook', () => Logbook);
最佳答案
你实际上导入了react-native两次。第二次它提示。只需摆脱
var React = require('react-native');
这做同样的事情,但是使用 ES6 模块语法
import React from 'react-native';
关于javascript - 我刚刚添加了 var React = require ('react-native' );我的整个构建失败了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34900399/