【发布时间】:2018-07-18 06:43:48
【问题描述】:
我正在使用这个主要依赖项开发一个反应原生应用程序:
- 原生反应
- 反应原生路由器通量
- 反应重击
- 世博会
我正在使用这个 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,所以我使用以下方式安装依赖项:
- 纱线安装
然后运行应用程序
- yarn start --reset-cache
我工作得很好,因为我想添加一个新的依赖项,所以我删除了 node_modules 文件夹和 yarn.lock 文件,添加了新的依赖项并再次执行 yarn install。
之后,打开应用程序时出现此错误:
TypeError: undefined is not a function (evalating 'addListener')
它与 react-navigation 相关,但我使用 react-native-router-flux 4.0.0-beta.24,内部使用 react-navigation ^1.0.0-beta.19。
我最近注意到使用 react-navigation 的人在使用 beta.28 版本时遇到了一些问题 (https://github.com/react-navigation/react-navigation/issues/3416)。
如果我回到以前的 node_modules 文件夹(从垃圾箱中),我的应用程序运行良好,所以.. 可能问题是我的 package.json 的 ^ 符号的某些依赖项不是更兼容.. 可能 thunk 或用我的反应原生版本反应原生路由器通量。
有什么想法吗?
这是我使用 react thunk 中间件时的代码部分:
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 版本之后..该应用程序适用于 beta 版本,但 1.0.0 版本存在此问题... 所以我意识到您在上一个版本(1.0.0-22.beta)中使用的是固定版本的反应导航
所以问题是,有没有办法仍然使用 RNRF 4.0.0-beta.24 但使用固定版本(例如 1.0.0-27.beta)?
我的意思是,我认为 4.0.0-beta.24 使用 ^1.0.0-beta19(这将导致安装最后一个 1.0.0 版本)和 4.0 等较新版本是没有意义的。 0-beta.28 使用固定的低版本(1.0.0-beta.22)
【问题讨论】:
标签: react-native redux react-navigation redux-thunk react-native-router-flux