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

使用Expo工作流时react-native-track-player报NativeEventEmitter非空参数错误

解决Expo托管工作流下react-native-track-player启动iOS报错问题

问题重现

使用Expo 49 + react-native-track-player 4.0.1,通过npx expo run:ios启动开发客户端时,iOS模拟器出现以下错误:

ERROR Invariant Violation: new NativeEventEmitter() requires a non-null argument., js engine: hermes
ERROR Invariant Violation: "main" 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

尚未编写播放服务注册代码,已尝试执行cd ios && pod install。

解决方案

1. 配置Expo Config Plugin

react-native-track-player是原生模块,在Expo托管工作流中必须通过config插件处理原生配置:
在app.json或app.config.js的expo字段中添加插件:

{
  "expo": {
    // 其他配置项
    "plugins": [
      "react-native-track-player"
    ]
  }
}

2. 清理缓存并重新构建

  • 完全停止Metro服务器及相关进程
  • 清理Expo缓存:
    npx expo start --clear
    
  • 清理iOS构建文件并重新安装Pods:
    rm -rf ios/build
    cd ios && pod deintegrate && pod install
    cd ..
    
  • 重新启动开发构建:
    npx expo run:ios
    

3. 确认App组件注册正确性

检查项目入口文件(如index.js或App.tsx)是否正确注册组件:

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

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

4. 验证版本兼容性

react-native-track-player 4.0.1支持React Native 0.70+,而Expo 49对应RN 0.72.x,版本匹配无需调整。

内容的提问来源于stack exchange,提问作者Robin Sadgehpour-Faraj

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 19:42:45