反应本机路由器通量:TypeError:未定义不是函数(评估“addListener") [英] React native router flux: TypeError: undefined is not a function (evaluating 'addListener')

查看:46
本文介绍了反应本机路由器通量:TypeError:未定义不是函数(评估“addListener")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此主要依赖项开发本机应用程序:

Im working on a react native app using this principal dependencies:

  • 反应原生
  • 反应原生路由器通量
  • 反应重击
  • 博览会

我正在使用这个 package.json:

I was working using this package.json:

"dependencies": {
    "expo": "23.0.4",
    "humps": "^2.0.0",
    "install": "^0.10.1",
    "lodash": "^4.17.4",
    "native-base": "^2.3.5",
    "react": "16.0.0",
    "react-native": "0.50.4",
    "react-native-extend-indicator": "^0.1.2",
    "react-native-keyboard-aware-scroll-view": "^0.4.2",
    "react-native-maps": "^0.19.0",
    "react-native-maps-directions": "^1.3.0",
    "react-native-modal-datetime-picker": "^4.13.0",
    "react-native-qrcode": "^0.2.6",
    "react-native-router-flux": "4.0.0-beta.24",
    "react-native-svg-uri": "^1.2.3",
    "react-native-swiper": "^1.5.13",
    "react-native-vector-icons": "^4.4.2",
    "react-navigation-redux-debouncer": "^0.0.2",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.2.0",
    "swagger-client": "2.1.32"
  }

该应用程序正在使用 expo,因此我使用以下方法安装依赖项:

The application is using expo so i install the dependencies using:

  • 纱线安装

然后通过

  • 纱线启动 --reset-cache

我工作正常,因为我想添加一个新的依赖项,所以我删除了 node_modules 文件夹和 yarn.lock 文件,添加了新的依赖项并再次执行 yarn install.

I was working fine since i wanted to add a new dependencie, so i remove the node_modules folder and the yarn.lock file, added the new dependencie and execute yarn install again.

之后,我在打开应用程序时收到此错误:

After that, im getting this error when opening the application:

TypeError: undefined 不是函数(评估addListener")

TypeError: undefined is not a function (evaluating 'addListener')

它与 react-navigation 相关,但我使用的是 react-native-router-flux 4.0.0-beta.24,它在内部使用 react-navigation ^1.0.0-beta.19.

it is related with react-navigation, but im using react-native-router-flux 4.0.0-beta.24 that uses react-navigation ^1.0.0-beta.19 internally.

我最近注意到使用 react-navigation 的人对此有一些麻烦(https://github.com/react-navigation/react-navigation/issues/3416) 但使用的是 beta.28 版本.

I have recently notice that people using react-navigation are having some troubbles with this (https://github.com/react-navigation/react-navigation/issues/3416) but using the beta.28 version.

如果我回到以前的 node_modules 文件夹(从垃圾箱),我的应用程序运行良好,所以.. 可能问题是我的 package.json 的 ^ 符号的某些依赖是没有的更兼容..也许用我的反应原生版本thunk或反应原生路由器通量.

If i go back to a previous node_modules folder (from the trash) my application runs well, so.. probably the thing is that some dependency with the ^ symbol of my package.json is no more compatible.. maybe thunk or react native router flux with my react native version.

有什么想法吗?

这是我使用 react thunk 中间件时的部分代码:

Here is the part of the code when i use the react thunk middleware:

import {applyMiddleware, compose, createStore} from 'redux';
import thunkMiddleware from 'redux-thunk';
import {createLogger} from 'redux-logger';
import getRootReducer from "../reducers/index";
import navigationDebouncer from 'react-navigation-redux-debouncer';
import {restApi} from "../lib/restApi";

const loggerMiddleware = createLogger({ predicate: (getState, action) => __DEV__  });

export default function getStore(initialState) {
    const enhancer = compose(
        applyMiddleware(
            thunkMiddleware.withExtraArgument(restApi),
            navigationDebouncer(600),
            loggerMiddleware
        ),
    );
    return createStore(
        getRootReducer,
        initialState,
        enhancer
    );
}

这里是主应用程序:

import React, {Component} from 'react';
import {Provider} from 'react-redux'
import getStore from './src/store/configureStore'
import {StatusBar} from 'react-native'
import AppNavigation from './src/navigation';

const Store = getStore();

export default class App extends Component {

    constructor(props) {
        super(props);
    }

    async componentWillMount() {
        await Expo.Font.loadAsync({
            'Ionicons': require('native-base/Fonts/Ionicons.ttf'),
        });
    }

    render() {
        StatusBar.setHidden(true);
        return (
            <Provider store={Store}>
                <AppNavigation/>
            </Provider>
        );
    }
}

我发现现在 react-native-router-flux 使用 1.0.0 react-navigation(新的稳定版本),在使用 1.0.0-beta.27 版本之后..该应用程序适用于测试版,但 1.0.0 版本存在此问题...所以我意识到您在上一个版本 (1.0.0-22.beta) 中使用的是固定版本的 React 导航

i have found that now react-native-router-flux uses 1.0.0 react-navigation (the new stable release), and after it was using the 1.0.0-beta.27 version.. the application works with the beta version but has this problem with the 1.0.0 version... so i realice that you are using a fixed version of react navigation in your last release (1.0.0-22.beta)

所以问题是,有没有办法仍然使用 RNRF 4.0.0-beta.24 但使用固定版本(例如 1.0.0-27.beta)?

so the question is, is there a way to still using RNRF 4.0.0-beta.24 BUT using a fixed version (like 1.0.0-27.beta for example) ?

我的意思是,我认为 4.0.0-beta.24 使用 ^1.0.0-beta19(这将导致安装最新的 1.0.0 版本)和像 4.0 这样的更新版本是毫无意义的.0-beta.28 使用固定的较低版本 (1.0.0-beta.22)

i mean, i think that is make no sence that 4.0.0-beta.24 uses ^1.0.0-beta19 (that will result in the installation of the last 1.0.0 release) and a newer version like 4.0.0-beta.28 uses a fixed lower version (1.0.0-beta.22)

推荐答案

所以在做了一些研究和一些测试之后,我想回答我的问题.

So after doing some research and some tests i want to answer my question.

问题在于内部处理 react-native-router-flux

依赖项是:

react-native-router-flux beta.0 - beta.24 -> react-navigation ^1.0.0-beta.19
react-native-router-flux beta.25 - beta.28 -> react-navigation 1.0.0-beta.22

这里的最大区别是从 0 到 beta24 的版本使用 ^

the big difference here is that versions from 0 to beta24 uses ^

那么..有什么问题吗?

安装依赖项时 beta24 会搜索自 1.0.0-beta.19 以来的最新版本 react-navigation,该版本是 react-navigation 的最新稳定版本 1.0.0(该库不再是 beta 版本)).

when installing the dependencies beta24 will search for the newest version of react-navigation since 1.0.0-beta.19, that version is the recent stable release 1.0.0 of react-navigation (the library is no more in beta version).

react-native-router-flux 不支持这种依赖.它也不提供对其他旧依赖项的支持,因此他们只是将 1.0.0-beta22 react-navigation 依赖项 固定在他们最新版本的 package.json 上(自测试版以来)26).

react-native-router-flux doesnt provide support for that dependency. It doesnt provide support to other olders dependencies neither, so they had just put the 1.0.0-beta22 react-navigation dependency fixed on their lastest releases package.json (since beta 26).

可能他们会修复它,因为有很多应用程序使用 redux 或其他与 react-native-router-flux 没有良好交互的库.

probably they will fix it since there are a lot of apps that use redux or other libraries that doesnt have good interaction with react-native-router-flux.

所以现在.. Redux 用户的解决方案是使用 beta26 版本,而对于不使用 redux 的人来说,beta27 和 beta28 可能没问题.

So for now.. the solution for Redux users is to go for the beta26 version, and for people that doesnt use redux probably beta27 and beta28 will be ok.

这里是讨论:https://github.com/aksonov/react-native-router-flux/issues/2865

这是另一个相关问题:https://github.com/aksonov/react-native-router-flux/issues/2799

这篇关于反应本机路由器通量:TypeError:未定义不是函数(评估“addListener")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆