我创建了一个空白项目whit expo init,然后我安装了react导航whit npm install @react-navigation/native
和expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view
,但当我运行应用程序whit expo start
我得到这个错误:无法从C:\Android\test\App.js解析模块@react-navigation/堆栈:在项目中找不到@react-navigation/stack。
错误截图:
App.js文件:
import * as React from 'react';
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
function HomeScreen() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
</View>
);
}
const Stack = createStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
我用来安装react-navigation的链接
我用来创建App.js here的链接
package.json文件:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@react-navigation/native": "^5.9.4",
"expo": "~41.0.0",
"expo-status-bar": "~1.0.4",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
"react-native-web": "~0.13.12",
"react-native-gesture-handler": "~1.10.2",
"react-native-reanimated": "~2.1.0",
"react-native-screens": "~3.0.0",
"react-native-safe-area-context": "3.2.0",
"@react-native-community/masked-view": "0.1.10"
},
"devDependencies": {
"@babel/core": "^7.9.0"
},
"private": true
}
节点版本:版本14.16.1
NPM版本:6.14.12
5条答案
按热度按时间rkue9o1l1#
按错误说的做
在终端NPM安装@React导航/堆叠或Yarn添加@React导航/堆叠
6rvt4ljy2#
您需要转到导入行并更改
import { createStackNavigator } from '@react-navigation/stack';
到
import { createStackNavigator } from '@react-navigation/native-stack';
guz6ccqo3#
我不认为react-navigation/stack是package.json中的依赖项。
如果您看到文档的第一步,它说“我们需要安装@react-navigation/stack”。
r1zhe5dt4#
我知道这已经有一段时间了,你可能已经找到了解决办法,但如果其他人有同样的问题,这里的解决办法:
你需要从
@React导航/堆栈
到@react-navigation/本机堆栈
使用npm重新安装
npm安装@React导航/本机堆栈
然后按如下方式导入:
从“@react-navigation/本机堆栈”导入{ createNativeStackNavigator }
nbnkbykc5#
跑步
npm install @react-navigation/native-stack
帮助我,并更新expo sdk到最新版本