react-native - React Navigation version 3 falied to load page
问题描述
I am using React Navigation 3.x and it failed to start the application. The error is below:-
This error is located at:
in StackViewLayout (at withOrientation.js:30)
in withOrientation (at StackView.js:96)
in RCTView (at View.js:60)
in View (at Transitioner.js:202)
in Transitioner (at StackView.js:22)
in StackView (at createNavigator.js:62)
in Navigator (at createKeyboardAwareNavigator.js:12)
in KeyboardAwareNavigator (at createAppContainer.js:388)
in NavigationContainer (at renderApplication.js:33)
in RCTView (at View.js:60)
in View (at AppContainer.js:102)
in RCTView (at View.js:60)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:32)
This error is located at:
in NavigationContainer (at renderApplication.js:33)
in RCTView (at View.js:60)
in View (at AppContainer.js:102)
in RCTView (at View.js:60)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:32)
My code goes here:-
Ap.js
import React from "react";
import { View, Text } from "react-native";
import { createStackNavigator, createAppContainer } from "react-navigation";
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Home Screen</Text>
</View>
);
}
}
const AppNavigator = createStackNavigator({
Home: {
screen: HomeScreen
}
});
export default createAppContainer(AppNavigator);
Package.json file is here:-
{
"name": "reactCrud",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.3.0-alpha.0",
"react-native": "0.55.0",
"react-native-gesture-handler": "^1.0.9",
"react-navigation": "^3.0.0"
},
"devDependencies": {
"babel-jest": "23.6.0",
"babel-preset-react-native": "4.0.1",
"jest": "23.6.0",
"react-test-renderer": "16.3.0-alpha.0"
},
"jest": {
"preset": "react-native"
}
}
To install react navigation I used these steps:-
npm install --save react-navigation
npm install --save react-native-gesture-handler
react-native link
How to solve this kind of error? Thanks in advance.
解决方案
我对 React Navigation V3 有同样的问题,我使用 Babel 7 的问题@babel/plugin-proposal-class-properties
所以我只是删除了所有不需要的插件我的 (.babelrc, babel.config.js) 如下所示:
{
"presets": [
"@babel/preset-flow",
"module:metro-react-native-babel-preset"
],
"plugins": [
["@babel/plugin-transform-runtime"],
["@babel/plugin-transform-flow-strip-types"],
['@babel/plugin-proposal-decorators', { legacy: true }]
]
}
它工作正常。但是你只需要安装上面的 babel 插件并配置你的 babel 配置文件,希望它能解决你的问题
推荐阅读
- assembly - 算术恒等式和 EFLAGS
- ansible - 如何在 docker 容器信息模块中省略容器
- linux - Linux 上的 HttpListener 请求队列超时
- c# - C#消费soap WS在VerifyIncomingMessage中返回安全头错误
- css - 如何在不使用固定宽度和高度的情况下制作以背景为中心的动画图像?
- mysql - 来自三个表的 MySQL “Inner Join”查询给出了错误的结果
- php - PHP - 如何调试空响应
- c++ - 遇到“无法识别'cl.exe'”和“c1xx:致命错误C1083:无法打开源文件:没有这样的文件或目录”错误
- python - 如何处理y轴python中的日期
- javascript - Javascript/sqlite3 SELECT LIKE 不起作用