You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决React Native Expo SDK40中Font全局API弃用警告

Fixing the Deprecated Expo.Font Global API Warning

Hey Marco, let's squash that deprecation warning for good! The root issue here is that you're relying on the global Expo.Font object instead of the module you already imported. Here's exactly how to fix it:

Step-by-Step Fix

  1. You already have the correct import for expo-font at the top of your file—great start:
    import * as Font from 'expo-font';
    
  2. Now just replace the global Expo.Font.loadAsync call in your componentDidMount method with the imported Font module you already have. That's the only change you need!

Modified Full Code

Here's your updated component with the fix applied:

// RNRF logic here
import React, { Component } from 'react';
import { StyleSheet, TouchableOpacity, Text, View } from 'react-native'
import AppLoading from 'expo-app-loading';
import * as Font from 'expo-font';
import { Ionicons } from '@expo/vector-icons';
import { Container, Root} from 'native-base';
import Constants from 'expo-constants';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isReady: false,
    };
  }

  async componentDidMount() {
    // Use the imported Font module instead of global Expo.Font
    await Font.loadAsync({
      'Roboto': require('native-base/Fonts/Roboto.ttf'),
      'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
      ...Ionicons.font,
    });
    this.setState({ isReady: true });
  }

  render(){
    if (!this.state.isReady) {
      return <AppLoading />;
    }
    return(
      <View>
        <Text>Hello</Text>
      </View>
    );
  }
}

Why This Works

Starting with Expo SDK 41, the global __expo and Expo objects are being phased out entirely. All Expo APIs (like expo-font) now require explicit module imports, which follows modern ES module best practices and ensures your app stays compatible with future Expo updates.

This change will fully resolve the warning without needing to ignore it—no more noisy logs cluttering up your dev environment!

内容的提问来源于stack exchange,提问作者Marco Martin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:13:27