rsnext/errors/no-script-component-in-head.mdx
Delba de Oliveira 44d1a1cb15
docs: Migrate error messages to MDX and App Router. (#52038)
This PR is part of a larger effort to migrate error messages to MDX and
use App Router: https://github.com/vercel/front/pull/23459
2023-07-05 06:11:16 -07:00

52 lines
972 B
Text

---
title: No Script Component in Head
---
> Prevent usage of `next/script` in `next/head` component.
## Why This Error Occurred
The `next/script` component should not be used in a `next/head` component.
## Possible Ways to Fix It
Move the `<Script />` component outside of `<Head>` instead.
**Before**
```jsx filename="pages/index.js"
import Script from 'next/script'
import Head from 'next/head'
export default function Index() {
return (
<Head>
<title>Next.js</title>
<Script src="/my-script.js" />
</Head>
)
}
```
**After**
```jsx filename="pages/index.js"
import Script from 'next/script'
import Head from 'next/head'
export default function Index() {
return (
<>
<Head>
<title>Next.js</title>
</Head>
<Script src="/my-script.js" />
</>
)
}
```
## Useful Links
- [next/head](/docs/pages/api-reference/components/head)
- [next/script](/docs/pages/building-your-application/optimizing/scripts)