martyjs / marty

A Javascript library for state management in React applications
http://martyjs.org
MIT License
1.09k stars 76 forks source link

server side rendering: "ReferenceError: self is not defined" #134

Closed vid closed 9 years ago

vid commented 9 years ago

I'm trying to do a server side prerender based on https://gist.github.com/koistya/24715d295fbf710d1e24

However, seeing this error:

if (self.fetch) {
      ^
ReferenceError: self is not defined

which from my browserified bundle is isomorphic-fetch/node_modules/whatwg-fetch/fetch.js:

[function(require,module,exports){
(function() {
  'use strict';

  if (self.fetch) {
    return
  }

which is a dependency of Marty.js.

Is it meant to work and could you provide an example?

Note I'm also using React-router but I haven't tried to tackle that yet.

Thanks!

AlanVerbner commented 9 years ago

@vid Isn't this related with issue https://github.com/jhollingworth/marty/issues/13 ?

vid commented 9 years ago

It might be, I am not sure what specific issues are stopping Marty from being isomorphic. But thanks to the pointer, though it's not clear where it's at.

AlanVerbner commented 9 years ago

@vid I think @jhollingworth is working on it (is tagged for v0.9). I guess you can find the progress here https://github.com/jhollingworth/marty/pull/114

vid commented 9 years ago

ok, thanks @AlanVerbner! I'll watch those two.

jhollingworth commented 9 years ago

Hey, can you check if you're NPM dependencies are up to date? I remember seeing something related to this ages ago but I believe it was fixed.

Also, as @AlanVerbner correctly points out, I'm actually working on making isomorphism super easy in v0.9 (#114). There are a loads of concurrency issues which need to be solved before it should be used in a prod environment

vid commented 9 years ago

I did update to the latest (0.8.12) and still saw the issue.

Checking out marty-express, wow!

jhollingworth commented 9 years ago

If there's any chance you could hold off on this until next week I think you will find isomorphisim will get a whole load easier :smile:

vid commented 9 years ago

Timing is perfect since I'll be on holiday till March 2. (=

jhollingworth commented 9 years ago

awesome! have a good holiday :sunglasses:

vid commented 9 years ago

thanks, and thanks for your good work!