Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 错误:MyDocument.getInitialProps()应解析为具有设置了有效html字符串的“html”属性的对象(在document.js中)_Reactjs - Fatal编程技术网

Reactjs 错误:MyDocument.getInitialProps()应解析为具有设置了有效html字符串的“html”属性的对象(在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

现在我正在用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:\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() }
}