Frank Gully
Frank Gully

Reputation: 267

Undefined is not an object (evaluating '_expo.Asset.loadAsync')

I'm creating a project with React-Native, and currently when I try to compile my code I get an error saying undefined is not an object (evaluating '_expo_.Asset.loadAsync')

I'm not entirely sure what had caused this, for I entered a lot of code prior to compiling the project. However, from what I gathered this may have something to do with the fonts I'm importing?

currently this is what my code looks like for importing the font.

async componentDidMount() {
    await cacheFonts({
      georgia: require('../assets/fonts/Georgia.ttf'),
      regular: require('../assets/fonts/Montserrat-Regular.ttf'),
      light: require('../assets/fonts/Montserrat-Light.ttf'),
    });

    this.setState({ fontLoaded: true });
  }

Upvotes: 1

Views: 2840

Answers (2)

Nico Lopez
Nico Lopez

Reputation: 66

This worked for me in similar code:

Install :

npm install expo-font

import * as Font from 'expo-font'; 
...
...

async componentDidMount() {
    await Font.loadAsync({
        'josefin-sans-regular': require('./assets/fonts/JosefinSans-Regular.ttf')
    });
    this.setState({ fontLoaded: true });
}

Upvotes: 5

hong developer
hong developer

Reputation: 13916

You didn't show the error-causing code. But you seem to have called in the entire module of Expo.

Maybe you used import * as Expo from "expo" and Expo.Asset.loadAsync

With SDK 33, we’re deprecating imports of most modules from the expo package. Each module must be installed and used.

You can run expo install expo-asset

import { Asset } from 'expo-asset';
...
Asset.loadAsync(modules)

If you want to use it as it is now, you can use this module. expo-codemod

Upvotes: 4

Related Questions