I encountered this error today,
document is not defined
ReferenceError: document is not defined
at Function._callee$ (/data/frank/image-website/.next/dist/pages/entity.js:95:72)
at tryCatch (/data/frank/image-website/node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (/data/frank/image-website/node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as next] (/data/frank/image-website/node_modules/regenerator-runtime/runtime.js:117:21)
at step (/data/frank/image-website/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /data/frank/image-website/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
at F (/data/frank/image-website/node_modules/core-js/library/modules/_export.js:35:28)
at Function.<anonymous> (/data/frank/image-website/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12)
at Function.getInitialProps (/data/frank/image-website/.next/dist/pages/entity.js:118:22)
at _callee$ (/data/frank/image-website/node_modules/next/dist/lib/utils.js:36:30)
No clue at all, any ideas? Thanks!
| Tech | Version |
|---------|---------|
| next | 3.0.1-beta.9 |
| node | v7.10.0 |
| OS | centos-release-7-3.1611.el7.centos.x86_64 |
| browser | Version 59.0.3071.115 (Official Build) (64-bit) |
Hi, you're using/writing some library the reply on DOM/ browser API. Since SSR is executed in node environment, the script won't have access to those API.
Consider wrapping your code in if (process.browser){} or put it in componentDidMount hook
It turns out I used document.cookie in getInitialProps(), after removing it everything is fine. Thanks!
Most helpful comment
Hi, you're using/writing some library the reply on DOM/ browser API. Since SSR is executed in node environment, the script won't have access to those API.
Consider wrapping your code in
if (process.browser){}or put it incomponentDidMounthook