我最近设置了react-native project with expo,后来添加了@react-navigation包。
似乎这还不够,因为NavigationContainer渲染抱怨SafeAreaContext
我试图用expo install react-native-safe-area-context ...安装所需的软件包,但它没有解决这个问题。
删除node_modules && npm install可能会有帮助,但也不起作用。
There were related questions to this issue,but they didn't provide much help
我会感谢你的帮助。。
这里是我在android仿真器中得到的

终端
Unable to resolve "./SafeAreaContext" from "node_modules\react-native-safe-area-context\src\index.tsx"
Failed building JavaScript bundle.App.tsx
import React, { useState } from 'react';
import { AppLoading } from 'expo'
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator } from '@react-navigation/stack';
function Test() {
return (
<View
style={{ flex: 1, justifyContent: 'space-between', alignItems: 'center' }}
>
<Text>Test</Text>
</View>
);
}
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
export default function App() {
const [loaded, setLoaded] = useState(false);
if(!loaded) {
return <AppLoading
startAsync={() => Promise.resolve()}
onFinish={() => setLoaded(true)}/>
}
return <NavigationContainer>
</NavigationContainer>
}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": {
"@expo/vector-icons": "^10.2.0",
"@react-native-community/masked-view": "^0.1.6",
"@react-navigation/bottom-tabs": "^5.5.1",
"@react-navigation/native": "^5.5.0",
"@react-navigation/stack": "^5.4.1",
"expo": "^37.0.12",
"expo-asset": "^8.1.5",
"expo-constants": "^9.0.0",
"expo-linking": "^1.0.1",
"expo-splash-screen": "^0.2.3",
"expo-web-browser": "^8.2.1",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-gesture-handler": "~1.6.0",
"react-native-reanimated": "~1.7.0",
"react-native-safe-area-context": "0.7.3",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "~2.2.0",
"react-native-web": "~0.11.7",
"react-redux": "^7.2.0",
"redux": "^4.0.5"
},
"devDependencies": {
"@babel/core": "^7.8.6",
"@types/react": "~16.9.23",
"@types/react-native": "~0.61.17",
"babel-preset-expo": "~8.1.0",
"typescript": "~3.8.3"
},
"private": true
}发布于 2020-06-05 11:10:52
Look like cleaning expo cache helped
expo r -c
expo r --help
Usage: start|r [options] [project-dir]
Starts or restarts a local server for your app and gives you a URL to it Options:
-c, --clear Clear the Metro bundler cache
....expo --version
3.21.3发布于 2021-03-19 11:19:22
安装以下两个,
npm install --save @react-native-community/masked-view
npm install react-native-safe-area-context这是我的工作
https://stackoverflow.com/questions/62205597
复制相似问题