问题描述
我在我的项目中使用了 react-navigation,并弹出这个错误.
I'm using react-navigation in my project, and this error pops up.
我在谷歌上搜索了这条错误信息,没有找到任何结果.
I googled this error message and found no result.
(我还不能发布图片)
错误信息如下:
`createStackNavigator()` has been moved to `react-navigation-stack`. See https://reactnavigation.org/docs/4.x/stack-navigator.html for more details.
代码在我朋友的机器上运行,不知何故
The code worked on my friend's machine, somehow
推荐答案
如错误所述,在 react-navigation
版本 4 中,所有导航器都已移至单独的 repos,因此您必须安装分别.
As said by the error, in react-navigation
version 4, all navigators have been moved to separate repos so you have to install them separately.
对于 StackNavigator
,您必须使用以下方法安装 react-navigation-stack
:
For the StackNavigator
you have to install react-navigation-stack
using:
npm i react-navigation-stack //or yarn add react-navigation-stack
之后,转到您定义 createStackNavigator
的文件并更改:
after that, go to the file where you define createStackNavigator
and change:
import { createStackNavigator } from 'react-navigation'
到:
import { createStackNavigator } from 'react-navigation-stack'
发生此错误的原因可能是您的朋友使用的是 react-navigation v. 3,但在您的 package.json
中,它使用的是 react-navigation
版本 >3.当您执行 npm install
时,它下载了最新版本的 react-navigation(上周更新到版本 4,并进行了这些更改)
This error may happen because your friend used react-navigation v. 3 but in your package.json
it's using a react-navigation
version >3. When you did npm install
it downloaded the latest version of react-navigation (that updated last week to version 4 with those changes)
其他导航器也是如此.
来源:https://reactnavigation.org/docs/en/stack-navigator.html
这篇关于`createStackNavigator()` 已移至 `react-navigation-stack`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!