警告:缺少下一个人数

Mic*_*l K 10 javascript head next.js

我正在使用 Next 文档中的自定义 _document.js 结果,我不断收到打印到控制台的警告消息。我尝试重新启动服务器并清空浏览器的缓存。我的 _document.js 应该在“pages”文件夹内。我通过向我的网站添加一些标签<Head>并检查我的网站以查看标签是否被添加到<Head>. (我的网站工作正常,我只是厌倦了这个警告消息。)

控制台警告:

Warning: next-head-count is missing. https://err.sh/next.js/next-head-count-missing
Run Code Online (Sandbox Code Playgroud)

这是我的 _document.js 文件:

import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx)
    return { ...initialProps }
  }

  render() {
    return (
      <Html>
        <Head>
          <link rel="icon" type="image/x-icon" href="/static/favicon.ico" />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    )
  }
}

export default MyDocument
Run Code Online (Sandbox Code Playgroud)

Ris*_*nha 12

当将不受支持的 html 标签添加到<Head>标签中时,也会出现此错误。

就我而言,我不小心在组件的标签<p>...</p>内添加了一个标签,从而引发了此错误。<Head>...</Head>


Mic*_*l K 6

显然我<head>在index.html 中也有一个标签。删除后错误就消失了。我的 _document.js 没有任何问题。我在单独的index.js 内部导入样式<head>,这就是发生错误的原因。

解决方案:我将<head>内容从index.js 移动到_document.js 并<head>从index.js 中删除了标签。

  • 就我而言,我在“next/head” Head 元素中有一个“&lt;html lang={lang}/&gt;”。显然不支持更改lang属性。 (3认同)

小智 6

<html lang="en" />我遇到了同样的问题,它与标签内部 有关<Head>