Javascript 未捕获错误:元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义

Javascript 未捕获错误:元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义,javascript,react-native,expo,google-fonts,Javascript,React Native,Expo,Google Fonts,我正在尝试在我的应用程序中使用google字体,当我尝试将其用作IBMPlexSans字体时,我遇到了这个错误。。。 '未捕获错误:元素类型无效:需要字符串(对于嵌入式组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了“默认导入”和“命名导入”。 谁能帮我一把吗 import React, { Component } from 'react' import { AppLoading } from 'expo' import { useF

我正在尝试在我的应用程序中使用google字体,当我尝试将其用作IBMPlexSans字体时,我遇到了这个错误。。。 '未捕获错误:元素类型无效:需要字符串(对于嵌入式组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了“默认导入”和“命名导入”。 谁能帮我一把吗

import React, { Component } from 'react'
import { AppLoading } from 'expo'
import {
  useFonts,
  IBMPlexSans_100Thin,
  IBMPlexSans_100Thin_Italic,
  IBMPlexSans_200ExtraLight,
  IBMPlexSans_200ExtraLight_Italic,
  IBMPlexSans_300Light,
  IBMPlexSans_300Light_Italic,
  IBMPlexSans_400Regular,
  IBMPlexSans_400Regular_Italic,
  IBMPlexSans_500Medium,
  IBMPlexSans_500Medium_Italic,
  IBMPlexSans_600SemiBold,
  IBMPlexSans_600SemiBold_Italic,
  IBMPlexSans_700Bold,
  IBMPlexSans_700Bold_Italic,
} from '@expo-google-fonts/ibm-plex-sans';

import { StyleSheet, Text, View, TouchableOpacity, ScrollView, Dimensions, ImageBackground } from 'react-native';




export default function RegisterScreen (props) {

    let [fontsLoaded] = useFonts({
        IBMPlexSans_100Thin,
        IBMPlexSans_100Thin_Italic,
        IBMPlexSans_200ExtraLight,
        IBMPlexSans_200ExtraLight_Italic,
        IBMPlexSans_300Light,
        IBMPlexSans_300Light_Italic,
        IBMPlexSans_400Regular,
        IBMPlexSans_400Regular_Italic,
        IBMPlexSans_500Medium,
        IBMPlexSans_500Medium_Italic,
        IBMPlexSans_600SemiBold,
        IBMPlexSans_600SemiBold_Italic,
        IBMPlexSans_700Bold,
        IBMPlexSans_700Bold_Italic,
      });
     
      if (!fontsLoaded) {
        return <AppLoading />;
      }

    return (

        <View>
           <Text style={{ fontFamily: 'IBMPlexSans_100Thin' }}>Text Example</Text>
        </View>
    )

}
import React,{Component}来自“React”
从“expo”导入{AppLoading}
进口{
使用字体,
IBMPlexSans_100Thin,
IBMPlexSans_100Thin_Italic,
IBMPlexSans_200ExtraLight,
IBMPlexSans_200ExtraLight_Italic,
IBMPlexSans_300灯,
IBMPlexSans_300浅斜体,
IBMPlexSansƐu常规,
IBMPlexSans\u 400常规\u斜体,
Imbplexsans_500中等,
IBMPlexSans_500中斜体,
IBMPlexSansɘ半黑体,
IBMPlexSans_600半黑体_斜体,
IBMPlexSans_700Bold,
IBMPlexSans_700Bold_斜体,
}来自“@expo google fonts/ibm plex sans”;
从“react native”导入{样式表、文本、视图、TouchableOpacity、ScrollView、维度、ImageBackground};
导出默认功能注册表屏幕(道具){
让[fontsLoaded]=使用字体({
IBMPlexSans_100Thin,
IBMPlexSans_100Thin_Italic,
IBMPlexSans_200ExtraLight,
IBMPlexSans_200ExtraLight_Italic,
IBMPlexSans_300灯,
IBMPlexSans_300浅斜体,
IBMPlexSansƐu常规,
IBMPlexSans\u 400常规\u斜体,
Imbplexsans_500中等,
IBMPlexSans_500中斜体,
IBMPlexSansɘ半黑体,
IBMPlexSans_600半黑体_斜体,
IBMPlexSans_700Bold,
IBMPlexSans_700Bold_斜体,
});
如果(!fontsLoaded){
返回;
}
返回(
文本示例
)
}

首先,像这样安装
expo-app-load

npm install expo-app-loading
import * as Font from 'expo-font';
import {
  IBMPlexSans_100Thin,
  IBMPlexSans_100Thin_Italic,
  IBMPlexSans_200ExtraLight,
  IBMPlexSans_200ExtraLight_Italic,
  IBMPlexSans_300Light,
  IBMPlexSans_300Light_Italic,
  IBMPlexSans_400Regular,
  IBMPlexSans_400Regular_Italic,
  IBMPlexSans_500Medium,
  IBMPlexSans_500Medium_Italic,
  IBMPlexSans_600SemiBold,
  IBMPlexSans_600SemiBold_Italic,
  IBMPlexSans_700Bold,
  IBMPlexSans_700Bold_Italic,
} from '@expo-google-fonts/ibm-plex-sans';

const useFonts = async () => {
  await Font.loadAsync({
    IBMPlexSans_100Thin,
    IBMPlexSans_100Thin_Italic,
    IBMPlexSans_200ExtraLight,
    IBMPlexSans_200ExtraLight_Italic,
    IBMPlexSans_300Light,
    IBMPlexSans_300Light_Italic,
    IBMPlexSans_400Regular,
    IBMPlexSans_400Regular_Italic,
    IBMPlexSans_500Medium,
    IBMPlexSans_500Medium_Italic,
    IBMPlexSans_600SemiBold,
    IBMPlexSans_600SemiBold_Italic,
    IBMPlexSans_700Bold,
    IBMPlexSans_700Bold_Italic,
  });
};

export default useFonts;
import React, { Component, useState } from 'react';
import AppLoading from 'expo-app-loading';

import {
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  ScrollView,
  Dimensions,
  ImageBackground,
} from 'react-native';

import useFonts from './hooks/useFonts';

export default function RegisterScreen(props) {
  const [IsReady, SetIsReady] = useState(false);

  const LoadFontsAndRestoreToken = async () => {
    await useFonts();
  };

  if (!IsReady) {
    return (
      <AppLoading
        startAsync={LoadFontsAndRestoreToken}
        onFinish={() => SetIsReady(true)}
        onError={() => {}}
      />
    );
  }

  return (
    <View>
      <Text style={{ fontFamily: 'IBMPlexSans_100Thin' }}>Text Example</Text>
      <Text>Normal Text</Text>
    </View>
  );
}
然后安装expo字体

npm install expo-font
App.js
所在的位置创建一个名为
hooks
的文件夹

hooks
文件夹中创建一个名为
useFonts.js的文件

那么您的
useFonts.js
应该如下所示

npm install expo-app-loading
import * as Font from 'expo-font';
import {
  IBMPlexSans_100Thin,
  IBMPlexSans_100Thin_Italic,
  IBMPlexSans_200ExtraLight,
  IBMPlexSans_200ExtraLight_Italic,
  IBMPlexSans_300Light,
  IBMPlexSans_300Light_Italic,
  IBMPlexSans_400Regular,
  IBMPlexSans_400Regular_Italic,
  IBMPlexSans_500Medium,
  IBMPlexSans_500Medium_Italic,
  IBMPlexSans_600SemiBold,
  IBMPlexSans_600SemiBold_Italic,
  IBMPlexSans_700Bold,
  IBMPlexSans_700Bold_Italic,
} from '@expo-google-fonts/ibm-plex-sans';

const useFonts = async () => {
  await Font.loadAsync({
    IBMPlexSans_100Thin,
    IBMPlexSans_100Thin_Italic,
    IBMPlexSans_200ExtraLight,
    IBMPlexSans_200ExtraLight_Italic,
    IBMPlexSans_300Light,
    IBMPlexSans_300Light_Italic,
    IBMPlexSans_400Regular,
    IBMPlexSans_400Regular_Italic,
    IBMPlexSans_500Medium,
    IBMPlexSans_500Medium_Italic,
    IBMPlexSans_600SemiBold,
    IBMPlexSans_600SemiBold_Italic,
    IBMPlexSans_700Bold,
    IBMPlexSans_700Bold_Italic,
  });
};

export default useFonts;
import React, { Component, useState } from 'react';
import AppLoading from 'expo-app-loading';

import {
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  ScrollView,
  Dimensions,
  ImageBackground,
} from 'react-native';

import useFonts from './hooks/useFonts';

export default function RegisterScreen(props) {
  const [IsReady, SetIsReady] = useState(false);

  const LoadFontsAndRestoreToken = async () => {
    await useFonts();
  };

  if (!IsReady) {
    return (
      <AppLoading
        startAsync={LoadFontsAndRestoreToken}
        onFinish={() => SetIsReady(true)}
        onError={() => {}}
      />
    );
  }

  return (
    <View>
      <Text style={{ fontFamily: 'IBMPlexSans_100Thin' }}>Text Example</Text>
      <Text>Normal Text</Text>
    </View>
  );
}
你的
App.js
应该是这样的

npm install expo-app-loading
import * as Font from 'expo-font';
import {
  IBMPlexSans_100Thin,
  IBMPlexSans_100Thin_Italic,
  IBMPlexSans_200ExtraLight,
  IBMPlexSans_200ExtraLight_Italic,
  IBMPlexSans_300Light,
  IBMPlexSans_300Light_Italic,
  IBMPlexSans_400Regular,
  IBMPlexSans_400Regular_Italic,
  IBMPlexSans_500Medium,
  IBMPlexSans_500Medium_Italic,
  IBMPlexSans_600SemiBold,
  IBMPlexSans_600SemiBold_Italic,
  IBMPlexSans_700Bold,
  IBMPlexSans_700Bold_Italic,
} from '@expo-google-fonts/ibm-plex-sans';

const useFonts = async () => {
  await Font.loadAsync({
    IBMPlexSans_100Thin,
    IBMPlexSans_100Thin_Italic,
    IBMPlexSans_200ExtraLight,
    IBMPlexSans_200ExtraLight_Italic,
    IBMPlexSans_300Light,
    IBMPlexSans_300Light_Italic,
    IBMPlexSans_400Regular,
    IBMPlexSans_400Regular_Italic,
    IBMPlexSans_500Medium,
    IBMPlexSans_500Medium_Italic,
    IBMPlexSans_600SemiBold,
    IBMPlexSans_600SemiBold_Italic,
    IBMPlexSans_700Bold,
    IBMPlexSans_700Bold_Italic,
  });
};

export default useFonts;
import React, { Component, useState } from 'react';
import AppLoading from 'expo-app-loading';

import {
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  ScrollView,
  Dimensions,
  ImageBackground,
} from 'react-native';

import useFonts from './hooks/useFonts';

export default function RegisterScreen(props) {
  const [IsReady, SetIsReady] = useState(false);

  const LoadFontsAndRestoreToken = async () => {
    await useFonts();
  };

  if (!IsReady) {
    return (
      <AppLoading
        startAsync={LoadFontsAndRestoreToken}
        onFinish={() => SetIsReady(true)}
        onError={() => {}}
      />
    );
  }

  return (
    <View>
      <Text style={{ fontFamily: 'IBMPlexSans_100Thin' }}>Text Example</Text>
      <Text>Normal Text</Text>
    </View>
  );
}
import React,{Component,useState}来自'React';
从“expo应用程序加载”导入应用程序加载;
进口{
样式表,
文本,
看法
可触摸不透明度,
滚动视图,
尺寸,
图像背景,
}从“反应本机”;
从“/hooks/useFonts”导入useFonts;
导出默认功能注册表屏幕(道具){
const[IsReady,SetIsReady]=useState(false);
const LoadFontsAndRestoreToken=async()=>{
等待使用字体();
};
如果(!IsReady){
返回(
SetIsReady(真)}
onError={()=>{}
/>
);
}
返回(
文本示例
普通文本
);
}