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

React Native Router Flux报错:addListener未定义,Expo项目重装依赖后触发

Fixing React Native Router Flux: TypeError: undefined is not a function (evaluating 'addListener') After Reinstalling Dependencies

Hey Marcos, sorry you're stuck with this frustrating error after resetting your dependencies—this kind of issue can pop up when version mismatches or stale cache sneak in. Let's walk through the most reliable fixes to get your app running again:

1. Lock in a Compatible RNRF Version

Chances are, deleting yarn.lock let Yarn pull in a newer (or incompatible) version of React Native Router Flux (RNRF) that clashes with your Expo/React Native setup.

  • If you have a backup of your old package.json or yarn.lock, hardcode the working RNRF version in your package.json (e.g., "react-native-router-flux": "^4.3.0" instead of a loose caret range).
  • If you don't have a backup, cross-reference RNRF's release notes with your Expo SDK version—for example, Expo SDK 49 pairs best with RNRF versions built for React Native 0.72.x.
  • Update the version in package.json, then run yarn install to pull the exact compatible build.

2. Do a Full Cache Reset

Partial cache clears often leave stale data behind. Let's wipe all related caches:

  • Run expo r -c—this is Expo's dedicated command to reset Metro and Expo caches, which is more thorough than yarn start --reset-cache.
  • If that doesn't work, manually delete the Expo cache directory: on macOS/Linux it's ~/.expo/cache, on Windows it's %USERPROFILE%\.expo\cache.
  • Add yarn cache clean to clear Yarn's local cache before reinstalling dependencies.

3. Double-Check Redux Store Integration

The addListener error can sometimes trace back to a misconfigured Redux store that RNRF depends on:

  • Make sure your store is properly set up with redux-thunk middleware. Your config should look like this:
    import { createStore, applyMiddleware } from 'redux';
    import thunk from 'redux-thunk';
    import rootReducer from './reducers';
    
    const store = createStore(rootReducer, applyMiddleware(thunk));
    export default store;
    
  • Confirm you're passing this correctly initialized store to RNRF's <Router> component:
    import { Router } from 'react-native-router-flux';
    import { Provider } from 'react-redux';
    import store from './store';
    
    const App = () => (
      <Provider store={store}>
        <Router>
          {/* Your scene definitions here */}
        </Router>
      </Provider>
    );
    

4. Isolate New Dependencies to Find Conflicts

Since this started after adding a new dependency, that package might be conflicting with RNRF:

  • Revert your package.json to the state before adding the new dependency, reinstall, and confirm the app works.
  • Add each new dependency one by one, running yarn install and yarn start after each addition. This will help you pinpoint which package is causing the issue.
  • Once you find the culprit, check for a compatible version of that package, or look for an alternative if needed.

5. Downgrade Expo/React Native (Last Resort)

If nothing else works, your current Expo SDK version might be too new for the latest RNRF releases:

  • Check RNRF's documentation to see which Expo SDK versions it officially supports.
  • Adjust your package.json to use a compatible SDK version (e.g., downgrade from SDK 50 to 49 if RNRF doesn't support 50 yet), then run yarn install and expo upgrade to sync all dependencies.

内容的提问来源于stack exchange,提问作者Marcos Martínez

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 04:22:23