I'm trying to load some fonts here and can't get rid of that error:
import { useFonts } from "expo-font";
import { Stack, SplashScreen } from "expo-router";
import { useEffect } from "react";
SplashScreen.preventAutoHideAsync();
const RootLayout = () => {
const [fontsLoaded, error] = useFonts({
"Poppins-Black": require("../assets/fonts/Poppins-Black.ttf"),
"Poppins-Bold": require("../assets/fonts/Poppins-Bold.ttf"),
"Poppins-ExtraBold": require("../assets/fonts/Poppins-ExtraBold.ttf"),
"Poppins-ExtraLight": require("../assets/fonts/Poppins-ExtraLight.ttf"),
"Poppins-Light": require("../assets/fonts/Poppins-Light.ttf"),
"Poppins-Medium": require("../assets/fonts/Poppins-Medium.ttf"),
"Poppins-Regular": require("../assets/fonts/Poppins-Regular.ttf"),
"Poppins-SemiBold": require("../assets/fonts/Poppins-SemiBold.ttf"),
"Poppins-Thin": require("../assets/fonts/Poppins-Thin.ttf"),
});
useEffect(() => {
if (error) {
console.log("Font Loading Error:", error); // Log the specific error
throw error;
}
if (fontsLoaded) {
console.log("Fonts Loaded Successfully!");
SplashScreen.hideAsync();
}
}, [fontsLoaded, error]);
if (!fontsLoaded) {
return null;
}
if (!fontsLoaded && !error) {
return null;
}
return (
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="(auth)" options={{ headerShown: false }} />
<Stack.Screen name="index" options={{ headerShown: false }} />
<Stack.Screen name="search/[query]" options={{ headerShown: false }} />
</Stack>
);
};
export default RootLayout;
Here's the package.json:
{
"name": "aora",
"version": "1.0.0",
"main": "expo-router/entry",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"@babel/runtime": "^7.24.4",
"@react-native/assets-registry": "0.75.0-main",
"expo": "~50.0.17",
"expo-constants": "~15.4.6",
"expo-font": "^11.10.3",
"expo-linking": "~6.2.2",
"expo-router": "~3.4.8",
"expo-status-bar": "~1.11.1",
"nativewind": "^2.0.11",
"react": "18.2.0",
"react-native": "0.73.6",
"react-native-safe-area-context": "4.8.2",
"react-native-screens": "~3.29.0"
},
"devDependencies": {
"@babel/core": "^7.24.4",
"tailwindcss": "3.3.2"
},
"private": true
}
Also, project structure and app.json:
root -> assets -> fonts
{
"expo": {
"name": "Aora",
"slug": "aora",
"scheme": "aora",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"./assets/**/*.{ttf,png}"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"web": {
"favicon": "./assets/favicon.png"
},
"plugins": [
"expo-router"
]
}
}
I've tried cleaning and rebuilding, uninstalling the @react-native/assets-registry package to see if it was a conflict with native Expo asset loading features, but it's an essencial package to the project. Can anyone help me with this?
After you updated to a new SDK you have to update other packages too.
npm install expo-constants@16.0.1 expo-font@12.0.5 expo-linking@6.3.1 expo-router@3.5.11 expo-status-bar@1.12.1 react-native@0.74.1 react-native-safe-area-context@4.10.1 react-native-screens@3.31.1 typescript@5.3.3