Reactjs 错误:MyDocument.getInitialProps()应解析为具有设置了有效html字符串的“html”属性的对象(在document.js中)
现在我正在用react+node js+next server+express制作一个小项目 发生了意想不到的错误 我不知道为什么_document.js中会出现错误 如果你知道原因,谢谢你让我知道 错误:Reactjs 错误:MyDocument.getInitialProps()应解析为具有设置了有效html字符串的“html”属性的对象(在document.js中),reactjs,Reactjs,现在我正在用react+node js+next server+express制作一个小项目 发生了意想不到的错误 我不知道为什么_document.js中会出现错误 如果你知道原因,谢谢你让我知道 错误: Error: "MyDocument.getInitialProps()" should resolve to an object with a "html" prop set with a valid html string at Object.renderToHTML (C:\n
Error: "MyDocument.getInitialProps()" should resolve to an object with a "html" prop set with a valid html string
at Object.renderToHTML (C:\node_bird_44\front\node_modules\next\dist\next-server\server\render.js:338:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
GET / 500 11240.415 ms - 21
[ event ] disposing inactive page(s): /, /_error
您缺少需要由getInitialProps返回的html道具。您可以从文档初始道具中获取此道具,如下所示:
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps, helmet: Helmet.renderStatic() }
}
你给我的解决方案奏效了。这对我来说是一个非常困难的问题。我很高兴能解决它。谢谢
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps, helmet: Helmet.renderStatic() }
}