rsnext/errors/no-styled-jsx-in-document.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

45 lines
1.5 KiB
Text

---
title: 'No `styled-jsx` in `_document`'
---
> Prevent usage of `styled-jsx` in `pages/_document.js`.
## Why This Error Occurred
Custom CSS like `styled-jsx` is not allowed in a [Custom Document](/docs/pages/building-your-application/routing/custom-document).
## Possible Ways to Fix It
If you need shared CSS for all of your pages, take a look at the [Custom `App`](/docs/pages/building-your-application/routing/custom-app) file or define a custom layout.
For example, consider the following stylesheet named `styles.css`:
```css filename="styles.css"
body {
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica',
'Arial', sans-serif;
padding: 20px 20px 60px;
max-width: 680px;
margin: 0 auto;
}
```
Create a `pages/_app.{js,tsx}` file if not already present. Then, import the `styles.css` file.
```jsx filename="pages/_app.js"
import '../styles.css'
// This default export is required in a new `pages/_app.js` file.
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
```
These styles (`styles.css`) will apply to all pages and components in your application.
## Useful Links
- [Custom Document Caveats](/docs/pages/building-your-application/routing/custom-document#caveats)
- [Layouts](/docs/pages/building-your-application/routing/pages-and-layouts#layout-pattern)
- [Built in CSS Support](/docs/pages/building-your-application/styling)
- [Custom `App`](/docs/pages/building-your-application/routing/custom-app)