2022-06-14 04:17:42 +02:00
|
|
|
# No Script Component in Head
|
|
|
|
|
|
|
|
> Prevent usage of `next/script` in `next/head` component.
|
2021-08-14 01:16:15 +02:00
|
|
|
|
|
|
|
#### Why This Error Occurred
|
|
|
|
|
2022-06-14 04:17:42 +02:00
|
|
|
The `next/script` component should not be used in a `next/head` component.
|
2021-08-14 01:16:15 +02:00
|
|
|
|
|
|
|
#### Possible Ways to Fix It
|
|
|
|
|
2022-06-14 04:17:42 +02:00
|
|
|
Move the `<Script />` component outside of `<Head>` instead.
|
2021-08-14 01:16:15 +02:00
|
|
|
|
|
|
|
**Before**
|
|
|
|
|
|
|
|
```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**
|
|
|
|
|
|
|
|
```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](https://nextjs.org/docs/api-reference/next/head)
|
|
|
|
- [next/script](https://nextjs.org/docs/basic-features/script#usage)
|