You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native引入MaterialIcons后VectorIcons未找到错误求助

React Native 引入MaterialIcons后出现VectorIcons未注册错误求助

在React Native项目中执行import MaterialIcons from '@react-native-vector-icons/material-icons';引入组件后,触发以下错误:

ERROR  Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'VectorIcons' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["PlatformConstants","LogBox","Timing","AppState","SourceCode","BlobModule","WebSocketModule","DevSettings","DevToolsSettingsManager","Networking","Appearance","DevLoadingView","HeadlessJsTaskSupport","UIManager","DeviceInfo","ImageLoader","SoundManager","IntentAndroid","DeviceEventManager"],"TurboModules":[],"NotFound":["NativePerformanceCxx","NativePerformanceObserverCxx","RedBox","BugReporting","LinkingManager","VectorIcons"]}, js engine: hermes
 LOG  Running "ProjectName" with {"rootTag":11}
 ERROR  Invariant Violation: "ProjectName" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes

移除MaterialIcons组件后错误消失。

项目的Index.js代码如下:

/**
 * @format
 */

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

使用的版本:

react-native-cli: 2.0.1
react-native: 0.74.2

已尝试以下操作但问题未解决:

  • 执行cd android && gradlew clean清理Gradle
  • 清除项目缓存
  • 通过npm start重启Metro服务
  • 在android/app/build.gradle中添加以下配置:
project.ext.vectoricons = [
    iconFontNames: [ 'MaterialIcons.ttf' ] // Adjust as necessary for other icon fonts
]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" 

恳请提供解决方案。

内容的提问来源于stack exchange,提问作者Daniel Aloyce Daniel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 20:24:59