`createStackNavigator()`已移至`react-navigation-stack`。

时间:2019-09-06 07:29:56

标签: react-native

我在项目中使用了反应导航,并且弹出此错误。

我搜索了此错误消息,但没有找到结果。

(我还不能发布图片)

错误消息显示为:

`createStackNavigator()` has been moved to `react-navigation-stack`. See https://reactnavigation.org/docs/4.x/stack-navigator.html for more details.

该代码可以在我朋友的机器上工作

11 个答案:

答案 0 :(得分:48)

如错误所言,在printf("%p, %lu\n", argv[i], strlen(argv[i])); 版本4中,所有导航器已移至单独的存储库,因此您必须单独安装它们。

对于Environment.CurrentDirectory,您必须使用以下命令安装D:\Projects\Trans\API

react-navigation

然后,转到定义StackNavigator的文件并更改:

react-navigation-stack

收件人:

npm i react-navigation-stack   //or yarn add react-navigation-stack

可能会发生此错误,因为您的朋友使用了反应导航v。3,但是在您的createStackNavigator中,它使用的是import { createStackNavigator } from 'react-navigation' 版本> 3。当您完成import { createStackNavigator } from 'react-navigation-stack' 时,它下载了最新版本的react-navigation(上周随着这些更改更新到了版本4)

其他导航器也是如此。

来源:https://reactnavigation.org/docs/en/stack-navigator.html

答案 1 :(得分:15)

  

在版本4中安装 react-navigation-stack NPM软件包,它将解决此问题。

对于StackNavigator,您必须使用以下命令安装react-navigation-stack:

npm install react-navigation-stack --save

检查https://reactnavigation.org/docs/en/hello-react-navigation.html以获得更多详细信息

import React from 'react';
import { View, Text } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

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);

答案 2 :(得分:5)

  1. npm install react-navigation-stack
  2. npm install react-navigation
  3. expo install react-native-gesture-handler react-native-reanimated
  4. Use app container

示例

import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

const RootStack = createStackNavigator({ /* your routes here */ });
const AppContainer = createAppContainer(RootStack);

// Now AppContainer is the main component for React to render
export default AppContainer;

答案 3 :(得分:4)

首先:安装

npm install react-navigation-stack

第二次:导入react-navigation-stack

import { createStackNavigator } from 'react-navigation-stack';

答案 4 :(得分:3)

在命令提示符下运行npm install @react-navigation/stackyarn add @react-navigation/stack,然后像import { createStackNavigator } from '@react-navigation/stack'一样导入它。我希望这会很好。有关更多信息,请read here

答案 5 :(得分:2)

您必须遵循两个步骤:

  1. yarn add react-navigation-stack npm install react-navigation-stack

  2. import { createStackNavigator } from "react-navigation-stack";

答案 6 :(得分:0)

更改(备注)

import { createStackNavigator } from 'react-navigation';

致(段落)

import { createStackNavigator } from 'react-navigation-stack';

答案 7 :(得分:0)

现在,依赖项是更改新的本机版本0.61

// old one
import {createStackNavigator} from 'react-navigation'; it's changed

// latest one 
first of all insatll the dependency 

npm install react-navigation-stack

import {createStackNavigator} from 'react-navigation-stack';  //this

export default createStackNavigator(
  {
   .....
  }

答案 8 :(得分:0)

在下面使用单行命令安装依赖项

npx expo-cli install react-native-gesture-handler react-native-reanimated react-navigation-stack

并如下更改导入语句

import { createStackNavigator } from 'react-navigation-stack';

答案 9 :(得分:0)

  

第1步:通过npm i react-navigation-stack安装createStackNavigator

     

第2步:将import { createStackNavigator } from "react-navigation-stack"; import { createAppContainer } from "react-navigation"; ----- 移至新创建的包中

createBottomTabNavigator

另外:

  

react-navigation-tabs也已从移至react-navigation   import { createBottomTabNavigator} from "react-navigation-tabs";

{{1}}

答案 10 :(得分:0)

我通过安装这些错误解决了同样的错误。

  1. npm install react-navigation
  2. npm我反应导航堆栈
  3. npm install react-native-anianied react-native-gesture-handler react-native-screens react-native-safe-area-context @ react-native-community / masked-view

然后我就放弃了

https://medium.com/better-programming/react-native-navigating-between-the-screens-and-code-structure-for-beginners-6b815ee8f79