Skip to content

ServerRouter transpiled incorrectly by Babel #3886

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

Closed
steida opened this issue Sep 17, 2016 · 9 comments
Closed

ServerRouter transpiled incorrectly by Babel #3886

steida opened this issue Sep 17, 2016 · 9 comments

Comments

@steida
Copy link
Contributor

steida commented Sep 17, 2016

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 = {};
steida added a commit to este/este that referenced this issue Sep 17, 2016
@timdorr timdorr changed the title ServerRouter probably wrong trenspiled in Node.js ServerRouter transpiled incorrectly by Babel Sep 17, 2016
@timdorr
Copy link
Member

timdorr commented Sep 17, 2016

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.

@Xerios
Copy link

Xerios commented Sep 17, 2016

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

@Xerios
Copy link

Xerios commented Sep 17, 2016

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.

@mjackson
Copy link
Member

Sounds like a Babel bug?

@apapirovski
Copy link

@mjackson It's not. Just no new 4.0.0 build on npm since this was committed 9eae410

@omaksi
Copy link

omaksi commented Sep 17, 2016

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

@iammerrick
Copy link
Contributor

Running into this issue too:
image

@iammerrick
Copy link
Contributor

v4.0.3 please! :-D

@timdorr
Copy link
Member

timdorr commented Sep 17, 2016

@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

@timdorr timdorr closed this as completed Sep 17, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants