未定义不是对象(评估'_expoFont.default.loadAsync')

时间:2019-07-07 05:18:46

标签: react-native expo

我遇到了这个问题,没有找到正确的答案。

undefined is not an object (evaluating '_expoFont.default.loadAsync')
* App.js:77:17 in _callee$
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:30 in invoke
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:28 in invoke
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:17 in <unknown>
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
- node_modules/promise/setimmediate/core.js:200:23 in doResolve
- node_modules/promise/setimmediate/core.js:66:12 in Promise
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:169:27 in callInvokeWithMethodAndArg
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:192:38 in enqueue
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:216:8 in async
* App.js:74:23 in _callee
- node_modules/expo/build/launch/AppLoading.js:13:22 in _callee$
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- ... 35 more stack frames from framework internals

这就是它的样子: enter image description here

这是App.js

  

从'expo'导入{AppLoading};       从“ expo-asset”导入{资产};       从'expo-font'导入字体;       从'react'导入React;       从'@ expo / vector-icons'导入{Feather};       从“ ./components”导入{块}       从“ ./navigation/AppNavigator”导入AppNavigator;       从'./navigation/MainTabNavigator'导入MainTabNavigator;

    // Firebase import ApiKeys from './constants/ApiKeys'; import * as firebase from 'firebase'

const images = [   require('./assets/icons/back.png'),   require('./assets/images/illustration_1.png'),  
     

require('./ assets / images / illustration_2.png'),
  require('./ assets / images / illustration_3.png'),
  require('./ assets / images / dealsBackground.png'),];

class App extends React.Component {
     constructor(props) {
    super(props);
    this.state = {
      isLoadingComplete: false,
      isAuthenticationReady: false,
      isAuthenticated: false,
    };

    // Initialize firebase...
    if (!firebase.apps.length) { firebase.initializeApp(ApiKeys.firebaseConfig); }
    firebase.auth().onAuthStateChanged(this.onAuthStateChanged);   }

  onAuthStateChanged = (user) => {
    this.setState({isAuthenticationReady: true});
    this.setState({isAuthenticated: !!user});   }

  render() {
    if ( (!this.state.isLoadingComplete || !this.state.isAuthenticationReady) && !this.props.skipLoadingScreen) {
      return (
        <AppLoading
          startAsync={this.loadResourcesAsync}
          onError={this._handleLoadingError}
          onFinish={this._handleFinishLoading}
        />
      );
    } else {
      return (
          <Block white>
            {(this.state.isAuthenticated) ? <MainTabNavigator /> : <AppNavigator />}
          </Block>
      );
    }   }

  loadResourcesAsync = async () => {
    return Promise.all([
      Asset.loadAsync(images),
      await Font.loadAsync(Feather.font)
    ]);   };

  _handleLoadingError = error => {
    // In this case, you might want to report the error to your error
    // reporting service, for example Sentry
    console.warn(error);   };

  _handleFinishLoading = () => {
    this.setState({ isLoadingComplete: true });   }; }

export default App;

我认为,我没有任何错误,并且该应用程序运行正常。

正确答案是:

import * as Font from 'expo-font';

1 个答案:

答案 0 :(得分:0)

正确的答案是将*导入为字体:

import * as Font from 'expo-font';