NextJS ReferenceError: window is not defined
rodrigooler opened this issue · 1 comments
rodrigooler commented
I'm using useWindowSize in the nextjs framework but I'm having these errors while using the lib. Here is an example of the error below.
Component:
import React from 'react'
import { useWindowSize } from 'the-platform'
const PublicContent = ({ children }: IProps) => {
const { height, width } = useWindowSize()
return (
<>
<MenuResponsive />
<PublicNavBar />
<Content height={height} width={width} background={COLOR.PURPLE}>
{children}
</Content>
</>
)
}
export default PublicContent
Error:
ReferenceError: window is not defined
at useWindowSize (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/the-platform/useWindowSize.js:31:12)
at PublicContent (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/src/.next/server/static/development/pages/index.js:5135:90)
at processChild (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:2750:14)
at resolve (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:2674:5)
at ReactDOMServerRenderer.render (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/react-dom/cjs/react-dom-server.node.developm
ent.js:3005:22)
at ReactDOMServerRenderer.read (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/react-dom/cjs/react-dom-server.node.developmen
t.js:2976:25)
at renderToString (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/react-dom/cjs/react-dom-server.node.development.js:3395:25)
at renderPage (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/next-server/dist/server/render.js:309:26)
at ctx.renderPage (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/src/.next/server/static/development/pages/_document.js:1363:26)
at Function.getInitialProps (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/src/.next/server/static/development/pages/_document.js:168:25)
at Function._callee$ (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/src/.next/server/static/development/pages/_document.js:1379:77)
at tryCatch (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/node_modules/regenerator-runtime/run
time.js:114:21)
at asyncGeneratorStep (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/src/.next/server/static/development/pages/_document.js:1314:103)
at _next (/Users/rodrigooler/projects/clubinvest-workstation/clubinvest/core/web-frontend/src/.next/server/static/development/pages/_document.js:1316:194)
package.json
"dependencies": {
"@zeit/next-typescript": "1.1.1",
"axios": "0.18.0",
"date-fns": "1.29.0",
"i18nh": "0.0.3",
"idx": "2.5.1",
"next": "v7.0.2-canary.27",
"nookies": "1.1.2",
"prop-types": "15.6.2",
"react": "16.7.0-alpha.0",
"react-autocomplete": "1.8.1",
"react-dom": "16.7.0-alpha.0",
"recompose": "0.30.0",
"reworm": "2.2.1",
"styled-components": "3.4.10",
"the-platform": "0.9.3"
},
rodrigooler commented
Apparently I found this report on the problem, it follows the issue with some information #44