[英]Unable to resolve “./SafeAreaContext”
我最近使用 expo 設置了react-native
項目,后來我添加了@react-navigation
包。
似乎這還不夠,因為NavigationContainer
渲染抱怨SafeAreaContext
我嘗試使用expo install react-native-safe-area-context...
安裝所需的軟件包,但沒有解決。
認為刪除node_modules
&& npm install
可能會有所幫助,但它也不起作用。
我會感謝你的幫助。
這是我在 android 仿真器中得到的
終端
Unable to resolve "./SafeAreaContext" from "node_modules\react-native-safe-area-context\src\index.tsx"
Failed building JavaScript bundle.
應用程序.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
}
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
安裝以下兩個,
npm install --save @react-native-community/masked-view
npm install react-native-safe-area-context
這對我有用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.