Skip to content

'ReferenceError: document is not defined' when used in server rendered React #9

@dsernst

Description

@dsernst

Adding Zenscroll leads to a fatal error in server-side rendered React applications.

Error

document is not defined

ReferenceError: document is not defined
    at createScroller (/Users/dsernst/Documents/my-project/node_modules/zenscroll/zenscroll.js:59:17)
    at /Users/dsernst/Documents/my-project/node_modules/zenscroll/zenscroll.js:209:24
    at defaultDuration (/Users/dsernst/Documents/my-project/node_modules/zenscroll/zenscroll.js:43:20)
    at Object.<anonymous> (/Users/dsernst/Documents/my-project/node_modules/zenscroll/zenscroll.js:47:2)
    at Module._compile (module.js:413:34)
    at Module._extensions..js (module.js:422:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/dsernst/Documents/my-project/node_modules/babel-core/lib/api/register/node.js:214:7)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)

This happens as soon as the module is imported. Still a problem even if none of its methods will be invoked during the server's pre-render.

Just needs to ensure document exists, and silently skip that function if not.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions