Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: _dispatch is not a function #1644

Closed
reggi opened this issue Apr 20, 2016 · 6 comments
Closed

TypeError: _dispatch is not a function #1644

reggi opened this issue Apr 20, 2016 · 6 comments

Comments

@reggi
Copy link
Contributor

reggi commented Apr 20, 2016

Here's the error:

[1] TypeError: _dispatch is not a function
[1]     at Object.dispatch (/Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/redux/lib/applyMiddleware.js:45:18)
[1]     at /Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/react-router-redux/lib/index.js:90:13
[1]     at /Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/history/lib/useQueries.js:109:9
[1]     at /Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/history/lib/useBasename.js:84:9
[1]     at Object.listen (/Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/history/lib/createHistory.js:104:7)
[1]     at Object.listen (/Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/history/lib/useBasename.js:83:22)
[1]     at Object.listen (/Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/history/lib/useQueries.js:108:22)
[1]     at middleware (/Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/react-router-redux/lib/index.js:83:34)
[1]     at /Users/thomas/Desktop/react-redux-universal-hot-example/node_modules/redux/lib/applyMiddleware.js:49:16
[1]     at Array.map (native)

Seems that a default value was removed in a commit (9496fd7) 11 days ago.

This line here needs access to dispatch and it's undefined.

Here's how to recreate the error:

git clone https://github.com/erikras/react-redux-universal-hot-example.git
cd react-redux-universal-hot-example
npm install
npm run dev
@calvinnwq
Copy link

To get around this for now until it is fixed, you will want to use v3.4.0 instead of v3.5.0.

@simonelp
Copy link

The problem is react-router-redux, update version to 4.0.2 and edit your code

@TomiS
Copy link

TomiS commented Apr 20, 2016

Updating react-router-redux didn't solve it for me. I had to revert back to 3.4.0 to get my app working.

I think there is something weird in this file:
https://github.com/reactjs/redux/blob/v3.5.0/src/applyMiddleware.js#L27

In version 3.5.0 it was changed so that line 27 can potentially call empty variable set on line 22. Even if this is intentional, it looks kinda weird to me.

This is how the file looks like after babel conversion:

function applyMiddleware() {
  for (var _len = arguments.length, middlewares = Array(_len), _key = 0; _key < _len; _key++) {
    middlewares[_key] = arguments[_key];
  }

  return function (createStore) {
    return function (reducer, initialState, enhancer) {
      var store = createStore(reducer, initialState, enhancer);
      var _dispatch;
      var chain = [];

      var middlewareAPI = {
        getState: store.getState,
        dispatch: function dispatch(action) {
          return _dispatch(action);
        }
      };
      chain = middlewares.map(function (middleware) {
        return middleware(middlewareAPI);
      });
      _dispatch = _compose2["default"].apply(undefined, chain)(store.dispatch);

      return _extends({}, store, {
        dispatch: _dispatch
      });
    };
  };
}

@gaearon
Copy link
Contributor

gaearon commented Apr 20, 2016

Thank you very much for reporting! Fixed in 3.5.1.

@andrewmclagan
Copy link

also encountered this issue, working as of 3.5.1 thanks! appreciated.

@khanhhaduc
Copy link

encountered the same issue, upgrading to 3.5.1 fixes perfectly. thanks for the promptly reply :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants