【发布时间】:2020-07-12 03:45:54
【问题描述】:
我正在尝试将 Font Awesome 集成到我正在开发的 React Native Expo 应用程序中,但我不断收到以下错误:
console.error: "ERROR: icon not found for icon = ", "coffee"
我只是按照以下 GitHub 页面上关于 React Native Font Awesome 的说明进行操作:https://github.com/FortAwesome/react-native-fontawesome
具体来说,首先,我运行了以下命令:
npm i --save react-native-svg #
npm i --save @fortawesome/fontawesome-svg-core
npm i --save @fortawesome/free-solid-svg-icons
npm i --save @fortawesome/react-native-fontawesome
这些都运行良好。然后我将以下内容添加到我的主屏幕代码中:
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
...
<FontAwesomeIcon icon="coffee" />
同样,我只是按照上面链接的 GitHub 页面上的说明进行操作。当我做所有这些时,我得到了上面提到的错误。根据我的package.json,我在expo 版本~36.0.0。
有什么想法吗?非常感谢您。
【问题讨论】:
-
在零食中试过它没有加载。因此,通过反应原生矢量图标添加了 fontawesome 图标,并且其完美运行示例:snack.expo.io/@msbot01/moody-strawberries
-
我跑了
npm install --save react-native-vector-icons,然后react-native link。一切都说成功了。然后我添加了import Icon from 'react-native-vector-icons/FontAwesome';,它起作用了,但是当我添加<Icon name="rocket" size={30} color="#900" />时,我得到了以下错误:console.error: "fontFamily "FontAwesome" is not a system font and has not been loaded through Font.loadAsync. ...。有任何想法吗?谢谢。 -
嘿塞巴斯蒂安...这里是相关线程(如果这没有帮助,请告诉我)---------->github.com/oblador/react-native-vector-icons/issues/789
-
我尝试了他们的建议,即删除
node_modules文件夹并再次尝试npm i,但这似乎让事情变得更糟。这样做之后,我在运行npm start时收到以下消息:Some of your project's dependencies are not compatible with currently installed expo package version: - react-native-svg - expected version range: 9.13.3 - actual version installed: ^12.0.3 Your project may not work correctly until you install the correct versions of the packages. To install the correct versions of these packages, please run: expo install [package-name ...] -
于是我运行了以下命令:
expo install react-native-svg。现在,当我什至尝试导入@fortawesome/react-native-fontawesome时,我会出现以下错误:Error: Requiring unknown module "undefined". If you are sure the module exists, try restarting Metro. You may also want to run 'yarn' or 'npm install'.有什么想法吗?
标签: react-native expo font-awesome react-font-awesome