我已经初始化了一个新的react-native应用程序,但是即使没有对代码进行任何更改,我也收到以下红色屏幕错误。
Java版本-8 节点-10.15.3 react-native-0.57.3
由于在较新版本中遇到许多错误,我已使用较低版本的react-native进行了初始化。我是本机反应的新手。请帮忙。
App.js文件。
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
export default class App 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 App.js</Text>
<Text style={styles.instructions}>{instructions}</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,
},
});
index.js
/** @format */
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
package.json
{
"name": "GoSurf",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.0-alpha.8af6728",
"react-native": "0.57.3"
},
"devDependencies": {
"babel-jest": "24.8.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.55.0",
"react-test-renderer": "16.6.0-alpha.8af6728"
},
"jest": {
"preset": "react-native"
}
}
显示的错误:-
https://drive.google.com/file/d/1-erzk1O-mZy6q-EuFBjE3qjhPgqmaMNA/view?usp=sharing
答案 0 :(得分:0)
从发布的代码来看,我猜想这与以下行有关:
<Text style={styles.instructions}>{instructions}</Text>
指令是对象而不是字符串
答案 1 :(得分:0)
否,{ instructions }
不是对象-至少我们不能从该代码段中看出。
只是说要让JSX在instructions
节点内注入<Text>
的值
我们今天也遇到了这个问题。原来,这是redux的最新更新。
恢复为redux@4.0.0
,错误就会消失