import Document, { Html, Head, Main, NextScript } from 'next/document';
class CustomDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx);
return { ...initialProps };
}
render() {
return (
<Html lang="en-US">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default CustomDocument;
我试图编辑此登录页,并输入
npm run dev
但是,显示如下错误:
Server Error
ReferenceError: window is not defined
This error happened while generating the page. Any console logs will be displayed in the terminal window.
pages_document.tsx (91:33) @ Function.getInitialProps
89 | }
90 |
> 91 | const { html, head } = await ctx.renderPage({ enhanceApp })
| ^
92 | const styles = [...flush()]
93 | return { html, head, styles }
94 | }
它还显示以下错误:
Call Stack
Function.getInitialProps
有人可以帮助解决这个错误吗?
谢谢。
我认为问题与样式组件的SSR有关,您可以在这里找到更多信息