admin管理员组文章数量:1178538
I'm using a custom _document.js from Next documentation. In result, I keep getting a warning message printed out to the console. I've tried to restart my server and emptied my browser's cache. My _document.js is inside a "pages" folder as it should be. I made sure that the file is being readen by adding some tags to my <Head>
and inspecting my website to see if the tag is being added to the <Head>
. (My website is working correctly I'm just tired of this warning message.)
Console warning:
Warning: next-head-count is missing. .js/next-head-count-missing
This is my _document.js file:
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
I'm using a custom _document.js from Next documentation. In result, I keep getting a warning message printed out to the console. I've tried to restart my server and emptied my browser's cache. My _document.js is inside a "pages" folder as it should be. I made sure that the file is being readen by adding some tags to my <Head>
and inspecting my website to see if the tag is being added to the <Head>
. (My website is working correctly I'm just tired of this warning message.)
Console warning:
Warning: next-head-count is missing. https://err.sh/next.js/next-head-count-missing
This is my _document.js file:
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
Share
Improve this question
asked Jun 15, 2020 at 9:34
Michal KMichal K
2332 gold badges3 silver badges10 bronze badges
2
|
7 Answers
Reset to default 12This error also shows up when an unsupported html tag is entered added into the <Head>
tag.
In my case I had accidentally added a <p>...</p>
tag within the <Head>...</Head>
tag in a component, which was throwing this error.
Apparently I had a <head>
tag inside index.html as well. After removing it the error was gone. There is nothing wrong with my _document.js. I was importing style in a separate <head>
inside index.js, that's why the error occurred.
Solution: I moved <head>
content from index.js to _document.js and removed the <head>
tag from index.js.
I had the same issue and it was related to the <html lang="en" />
inside the <Head>
tag.
In my case, there was an incorrect html tag inside next's Head component. 90% of this error means that something wrong with the content inside Head. Try to remove elements inside Head one by one and you will find what causes the issue.
In my case, the Head component imported from next/Document was in the custom _document, but it was within the body tag, moving it within the Html component and outside of the body tag fixed it.
// Incorrect
export default class MyDocument extends Document {
render (): JSX.Element {
return (
<Html>
<body>
<Head />
<Main />
<NextScript />
</body>
</Html>
);
}
}
// Correct
export default class MyDocument extends Document {
render (): JSX.Element {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
In my case "Convert HTML to JSX" vscode extension added a wrapper div tag in the next/head component. I removed div tag and the warning gone.
For me, I had a custom component <MobileView>
in the <Head>
.
So changing that did the trick.
本文标签: javascriptWarning nextheadcount is missingStack Overflow
版权声明:本文标题:javascript - Warning: next-head-count is missing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738074151a2059290.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
_document.js
looks fine to me. Have you tried removing the.next
folder and start the dev server again? – hangindev.com Commented Jun 16, 2020 at 2:38