ssuhat
ssuhat

Reputation: 7656

Redux Router Uncaught TypeError: createHistory is not a function

Redux Router Version ^2.1.2

react-router version: "react-router": "^3.0.0", history version: "history": "^4.3.0",

Steps to reproduce

    import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import { Router, browserHistory } from 'react-router';
import { reduxReactRouter, routerStateReducer, ReduxRouter } from 'redux-router';
import reduxThunk from 'redux-thunk';
import { createHistory } from 'history';

import rootReducer from './core/rootReducer';
import routes from './core/routes';

import * as axios from './utils/axios.js';

import { AUTH_USER } from './authentication/types';

const store = compose(applyMiddleware(reduxThunk),
    reduxReactRouter({ routes, createHistory })
)(createStore)(rootReducer);

const token = localStorage.getItem('token');

if (token) {
    store.dispatch({ type: AUTH_USER });
}

ReactDOM.render(
    <Provider store={store}>
        <ReduxRouter>

            {routes}

        </ReduxRouter>
    </Provider>
    , document.querySelector('.main')
);

It return an error index.js:34416 Uncaught TypeError: createHistory is not a function(…)

Any solution?


After changing import { createHistory } from 'history'; to import createHistory from 'history/createBrowserHistory';

The error become Uncaught TypeError: history.getCurrentLocation is not a function

Thoughts?

Upvotes: 2

Views: 4230

Answers (1)

xanld
xanld

Reputation: 1067

I fixed this by specifying version 3 of history in my package.json

"history": "^3.0.0",

react-router 3.0.0 specifies history 3.0.0 as a dependancy, but for some reason it isn't added to node_modules. But adding it explicitly to your own package.json fixed the problem for me.

I don't think react-router 3.0.0 is yet compatible with history v4. I'm not sure why npm is not observing the dependancy in react-router v3.0.0 package.json

Upvotes: 5

Related Questions