diff --git a/errors/manifest.json b/errors/manifest.json index 6cbe3fa51e0ec9a..918ca43deb74b7b 100644 --- a/errors/manifest.json +++ b/errors/manifest.json @@ -427,6 +427,14 @@ "title": "sharp-missing-in-production", "path": "/errors/sharp-missing-in-production.md" }, + { + "title": "script-in-document-page", + "path": "/errors/no-script-in-document-page.md" + }, + { + "title": "script-in-head-component", + "path": "/errors/no-script-in-head-component.md" + }, { "title": "max-custom-routes-reached", "path": "/errors/max-custom-routes-reached.md" diff --git a/errors/no-script-in-document-page.md b/errors/no-script-in-document-page.md new file mode 100644 index 000000000000000..201d01d32e24a74 --- /dev/null +++ b/errors/no-script-in-document-page.md @@ -0,0 +1,27 @@ +# Script component inside \_document.js + +#### Why This Error Occurred + +You can't use the `next/script` component inside the `_document.js` page. That's because the `_document.js` page only runs on the server and `next/script` has client-side functionality to ensure loading order. + +#### Possible Ways to Fix It + +If you want a global script, instead use the `_app.js` page. + +```jsx +import Script from 'next/script' + +function MyApp({ Component, pageProps }) { + return ( + <> + + + ); + } + `, + ], + + invalid: [ + { + code: ` + import Head from "next/head"; + import Script from "next/script"; + + export default function Index() { + return ( + + + + ); + }`, + filename: 'pages/index.js', + errors: [ + { + message: + "next/script shouldn't be used inside next/head. See: https://nextjs.org/docs/messages/no-script-in-head-component ", + }, + ], + }, + ], +})