2023-07-05 15:11:16 +02:00
|
|
|
---
|
|
|
|
title: No Duplicate Head
|
|
|
|
---
|
2021-07-15 20:04:17 +02:00
|
|
|
|
2022-06-14 04:17:42 +02:00
|
|
|
> Prevent duplicate usage of `<Head>` in `pages/_document.js`.
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
## Why This Error Occurred
|
2021-07-15 20:04:17 +02:00
|
|
|
|
|
|
|
More than a single instance of the `<Head />` component was used in a single custom document. This can cause unexpected behavior in your application.
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
## Possible Ways to Fix It
|
2021-07-15 20:04:17 +02:00
|
|
|
|
|
|
|
Only use a single `<Head />` component in your custom document in `pages/_document.js`.
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
```jsx filename="pages/_document.js"
|
2021-07-15 20:04:17 +02:00
|
|
|
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
|
|
|
|
|
|
|
class MyDocument extends Document {
|
|
|
|
static async getInitialProps(ctx) {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Html>
|
|
|
|
<Head />
|
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</Html>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MyDocument
|
|
|
|
```
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
## Useful Links
|
2021-07-15 20:04:17 +02:00
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
- [Custom Document](/docs/pages/building-your-application/routing/custom-document)
|