反应本机错误 "make sure to start component names with a capital letter" 但他们是

React native error "make sure to start component names with a capital letter" BUT THEY ARE

我在 React Native 中遇到的错误很常见,但在 中找到的解决方案始终是确保 React 组件以 大写字母开头 .

但是,导致问题的组件已经大写

导致我的 App.js 问题的组件是:

<FontAwesomeIcon icon={faCannabis}>

完整代码供参考:

import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
// get our fontawesome imports
import { faHome } from "@fortawesome/free-solid-svg-icons";
import { faCannabis } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

export default function App() {
  return (
    <View>
      <Text>My APP</Text>
      <Text>
        <FontAwesomeIcon icon={faCannabis}></FontAwesomeIcon>
      </Text>
      <StatusBar style="auto" />
    </View>
  );
}

另一个令人困惑的部分是,当使用 Expo 时,应用程序在网络上运行良好,但在 android 或 iOS 上,它会抛出常见错误

Invariant Violation: View config getter callback for component 'path' must be a function (received undefined). Make sure to start component names with a capital letter

但是他们是大写的!

还有什么可能导致此问题?

您应该使用 react-native 版本的 font-awesome。 检查 snack here

import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";

import { faHome } from "@fortawesome/free-solid-svg-icons";
import { faCannabis } from "@fortawesome/free-solid-svg-icons";
// use the react native version of the package
import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";

export default function App() {
  return (
    <View>
      <Text>My APP</Text>
      <Text>
        <FontAwesomeIcon icon={faCannabis}></FontAwesomeIcon>
      </Text>
      <StatusBar style="auto" />
    </View>
  );
}