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

执行addListener触发TypeError:undefined不是函数,求解决方案

解决方案:依赖版本不兼容导致的addListener TypeError

我之前也碰到过一模一样的问题!你说得没错,这绝对不是代码逻辑问题,就是更新后依赖包版本不匹配搞出来的麻烦。

问题根源

你用的react-native-router-flux@4.0.0-beta.30这个beta版本,它依赖的react-navigation版本和你当前的expo@25.0.1、react-native@0.52.3不兼容。新版本的react-navigation里调整了事件订阅相关的API,而旧版React Native/Expo的导航组件没有对应的方法,就抛出了undefined is not a function (evaluating 'addListener')这个错误。

具体修复步骤

  1. 清理旧依赖:先删掉本地的依赖包和锁定文件,避免缓存影响
# npm用户
rm -rf node_modules package-lock.json

# yarn用户
rm -rf node_modules yarn.lock
  1. 调整react-native-router-flux版本:把它降级到和你的Expo 25兼容的beta版本,比如4.0.0-beta.28,修改你的package.json里的依赖项:
"dependencies": {
  // ... 其他依赖保持不变
  "react-native-router-flux": "^4.0.0-beta.28",
}
  1. 重新安装依赖:
npm install
# 或者 yarn install
  1. 可选:锁定react-navigation版本
    如果还是有问题,可以在package.json里明确指定兼容的react-navigation版本,因为react-native-router-flux会自动安装它,但有时候版本解析会出问题:
"dependencies": {
  // ... 其他依赖
  "react-navigation": "1.5.11",
}

做完这些步骤后,重新启动你的Expo项目,这个错误应该就消失了。

内容的提问来源于stack exchange,提问作者Adam Duffield

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 06:45:08