React-rails: setTimeout is not defined

Created on 14 Dec 2015  路  5Comments  路  Source: reactjs/react-rails

I'm having some problems using a data-grid module (fixed-data-table). I'm using the webpack distribution. I always see this error in pre-render:

TypeError: Object # has no method 'setTimeout'

The Object in question is "global" which in most cases I'd assume would be window. I'm not sure what it ends up being within the react-rails pre-render. I'm guessing the pre-render environment doesn't provide these. Surely all JS environments should provide these methods?

Most helpful comment

I've gotten around this by adding this at the top of the generated webpack, but would like a better solution.

(function (global) {
global.clearTimeout = global.clearTimeout || function () {};
global.setTimeout = global.setTimeout || function () {};
}(this));

Essentially this means any methods passed to setTimeout will never be called, which should be fine for rendering purposes.

All 5 comments

Looks like ExecJS doesn't support setTimeout: https://github.com/rails/execjs#faq (Or therubyracer: https://github.com/cowboyd/therubyracer/issues/325)

I've gotten around this by adding this at the top of the generated webpack, but would like a better solution.

(function (global) {
global.clearTimeout = global.clearTimeout || function () {};
global.setTimeout = global.setTimeout || function () {};
}(this));

Essentially this means any methods passed to setTimeout will never be called, which should be fine for rendering purposes.

Glad you found a workaround!

@tbrd May I ask how you added that to the generated webpack? is there a way I can set in config to write that to the top of the compiled file? thanks.

@tbrd I cannot figure out where to define the function in webpack.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hugofloss picture hugofloss  路  4Comments

ttanimichi picture ttanimichi  路  4Comments

axhamre picture axhamre  路  3Comments

ghost picture ghost  路  4Comments

chrismv48 picture chrismv48  路  3Comments