“React ‘view config getter callback component ‘path’ must be function (received ‘undefined’)”

huangapple go评论65阅读模式
英文:

React "view config getter callback component 'path' must be function (received 'undefined')"

问题

我无法在我的React应用程序中使用React图标。我可以很好地导入FontAwesome图标,但每当我尝试使用该图标时,我的应用程序就会崩溃。我尝试过从Stack Overflow和其他网站上找到的许多答案,但都没有帮助。有人可以帮我吗?以下是我的App.js:

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import { FaArrowLeft } from "@react-icons/all-files/fa/FaArrowLeft";

export default function App() {
  return (
      <View style={styles.container}>
        <Text>
          主页 <FaArrowLeft />
        </Text>
        <StatusBar style="auto" />
      </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'skyblue',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

在移动应用程序上显示的错误是:视图配置获取器回调组件 'path' 必须是一个函数(接收到 'undefined')

在VS Code上显示的错误的前几行是:

错误:无法解析模块./Libraries/Components/DatePicker/DatePickerIOS来自/Users/Dakota/Mobile/Recifeed/node_modules/react-native/index.js:

没有这些文件:
  * node_modules/react-native/Libraries/Components/DatePicker/DatePickerIOS(.native|.native.ts|.ts|.native.tsx|.tsx|.native.js|.js|.native.jsx|.jsx|.native.json|.json)
  * node_modules/react-native/Libraries/Components/DatePicker/DatePickerIOS/index(.native|.native.ts|.ts|.native.tsx|.tsx|.native.js|.js|.native.jsx|.jsx|.native.json|.json)
  15 | import typeof ActivityIndicator from './Libraries/Components/ActivityIndicator/ActivityIndicator';
  16 | import typeof Button from './Libraries/Components/Button';
  17 | import typeof DatePickerIOS from './Libraries/Components/DatePicker/DatePickerIOS';
     |                                   ^

最常见的解决方法是运行 npm start --clean-cache,但对我不起作用。

英文:

I can't get a react icon inside my react app. I can import the font awesome icon just fine, but whenever I try using the icon, my app crashes. I've tried dozens of answers from stack overflow and other websites and none of those have helped. Can some help me with this? Here's my App.js

import { StyleSheet, Text, View } from &#39;react-native&#39;;
import { FaArrowLeft } from &quot;@react-icons/all-files/fa/FaArrowLeft&quot;;

export default function App() {
  return (
      &lt;View style={styles.container}&gt;
        &lt;Text&gt;
          Main &lt;FaArrowLeft /&gt;
        &lt;/Text&gt;
        &lt;StatusBar style=&quot;auto&quot; /&gt;
      &lt;/View&gt;
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: &#39;skyblue&#39;,
    alignItems: &#39;center&#39;,
    justifyContent: &#39;center&#39;,
  },
});

The error that shows up on the mobile app is:
view config getter callback component &#39;path&#39; must be function (received &#39;undefined&#39;)

And the first couple lines of the error that shows up on vs code is:

Error: Unable to resolve module ./Libraries/Components/DatePicker/DatePickerIOS from /Users/Dakota/Mobile/Recifeed/node_modules/react-native/index.js: 

None of these files exist:
  * node_modules/react-native/Libraries/Components/DatePicker/DatePickerIOS(.native|.native.ts|.ts|.native.tsx|.tsx|.native.js|.js|.native.jsx|.jsx|.native.json|.json)
  * node_modules/react-native/Libraries/Components/DatePicker/DatePickerIOS/index(.native|.native.ts|.ts|.native.tsx|.tsx|.native.js|.js|.native.jsx|.jsx|.native.json|.json)
  15 | import typeof ActivityIndicator from &#39;./Libraries/Components/ActivityIndicator/ActivityIndicator&#39;;
  16 | import typeof Button from &#39;./Libraries/Components/Button&#39;;
&gt; 17 | import typeof DatePickerIOS from &#39;./Libraries/Components/DatePicker/DatePickerIOS&#39;;
     |                                   ^
  18 | import typeof DrawerLayoutAndroid from &#39;./Libraries/Components/DrawerAndroid/DrawerLayoutAndroid&#39;;
  19 | import typeof FlatList from &#39;./Libraries/Lists/FlatList&#39;;
  20 | import typeof Image from &#39;./Libraries/Image/Image&#39;;
    at ModuleResolver.resolveDependency (/Users/Dakota/Mobile/Recifeed/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:136:15)
    at DependencyGraph.resolveDependency (/Users/Dakota/Mobile/Recifeed/node_modules/metro/src/node-haste/DependencyGraph.js:231:43)
    at Object.resolve (/Users/Dakota/Mobile/Recifeed/node_modules/metro/src/lib/transformHelpers.js:129:24)
    at resolve (/Users/Dakota/Mobile/Recifeed/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:33)
    at /Users/Dakota/Mobile/Recifeed/node_modules/metro/src/DeltaBundler/traverseDependencies.js:412:26
    at Array.reduce (&lt;anonymous&gt;)

The most common resolution is running 'npm start --clean-cache' but that doesn't work for me

答案1

得分: 0

您不能在React Native中使用@react-icons/all-filesreact-icons。它们渲染Web原生的<svg>标签,在RN中不起作用。如果您想要在RN中使用图标,您可以考虑以下选项:

  • react-native-vector-icons(适用于裸机React Native项目)
  • @expo/vector-icons(适用于Expo托管应用程序)

这些选项与Web React的版本(react-icons)不同,并为每个平台渲染本机组件,而不是<svg>

英文:

You cannot use @react-icons/all-files nor react-icons in React Native. They render web-native &lt;svg&gt; tags which won't work in RN. If you want icons in RN they you might consider looking into either

  • react-native-vector-icons (If you have a bare React Native project)
  • @expo/vector-icons (For an expo managed application)

These are different from the web React's version (react-icons) & render native components for each platform instead of an &lt;svg&gt;.

huangapple
  • 本文由 发表于 2023年7月7日 03:44:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632102.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定