首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解决"./SafeAreaContext“

无法解决"./SafeAreaContext“
EN

Stack Overflow用户
提问于 2020-06-04 23:08:08
回答 2查看 3.4K关注 0票数 5

我最近设置了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 issuebut they didn't provide much help

我会感谢你的帮助。

这里是我在android仿真器中得到的

终端

代码语言:javascript
复制
Unable to resolve "./SafeAreaContext" from "node_modules\react-native-safe-area-context\src\index.tsx"
Failed building JavaScript bundle.

App.tsx

代码语言:javascript
复制
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

代码语言:javascript
复制
{
  "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
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-05 11:10:52

Look like cleaning expo cache helped

expo r -c

expo r --help

代码语言:javascript
复制
Usage: start|r [options] [project-dir]
Starts or restarts a local server for your app and gives you a URL to it
代码语言:javascript
复制
 Options:
    -c, --clear           Clear the Metro bundler cache
   ....
代码语言:javascript
复制
expo --version
3.21.3
票数 12
EN

Stack Overflow用户

发布于 2021-03-19 11:19:22

安装以下两个,

代码语言:javascript
复制
npm install --save @react-native-community/masked-view

npm install react-native-safe-area-context

这是我的工作

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62205597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档