React-router: ServerRouter transpiled incorrectly by Babel

Created on 17 Sep 2016  路  9Comments  路  Source: ReactTraining/react-router

Version

4.0.0

I got this error:

ReferenceError: location is not defined
   at ServerRouter.render (/Users/este/dev/este/node_modules/react-router/ServerRouter.js:58:19)

So I checked transpiled code:

}, {
    key: 'render',
    value: function render() {
      var _props = this.props;
      var context = _props.context;

      var rest = _objectWithoutProperties(_props, ['context']);

      var redirect = function redirect(location) {
        context.setRedirect(location);
      };
      return _react2.default.createElement(_StaticRouter2.default, _extends({
        action: 'POP',
        location: location,
        onReplace: redirect,
        onPush: redirect
      }, rest));
    }
  }]);

Note location is retrieved from global state. Node.js does not have it.

This is temp fix

global.location = {};

Most helpful comment

v4.0.3 please! :-D

All 9 comments

That's pretty wacky. Your fix isn't correct, as the location you need to be referencing comes from props. I believe it's the arrow function and the scoping is interacting oddly with the object destructuring. I wouldnt be surprised if renaming the local variable to loc would fix it.

Same here, compiling the library directly seems to work fine.
Somehow, babel misses the location variable deconstruction.

For those who are looking for a quick dirty fix (ServerRouter.js):

    var location = _props.location; // Add this line after "var context =  _props.context;"
    var rest = _objectWithoutProperties(_props, ['context', 'location']); // Add missing 'location' to the array

I've locally packed and installed it with no problems.
Seems like it's just a bad transpile job, could someone republish with proper transpilation?
Thanks.

Sounds like a Babel bug?

@mjackson It's not. Just no new 4.0.0 build on npm since this was committed https://github.com/ReactTraining/react-router/commit/9eae41003ac6dc8ec1df862657f60c85a6104626

So any guess on when can we expect the next v4 npm build? :)

Running into this issue too:
image

v4.0.3 please! :-D

@iammerrick We haven't released 4.0.0 yet, so why would we do 4.0.3? 馃槈

4.0.0-alpha.3 is out: https://github.com/ReactTraining/react-router/releases/tag/v4.0.0-alpha.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Waquo picture Waquo  路  3Comments

wzup picture wzup  路  3Comments

nicolashery picture nicolashery  路  3Comments

jzimmek picture jzimmek  路  3Comments

ArthurRougier picture ArthurRougier  路  3Comments