rsnext/errors/no-server-import-in-page.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

25 lines
628 B
Text

---
title: No Server Import In Page
---
> Prevent usage of `next/server` outside of `middleware.js`.
## Why This Error Occurred
`next/server` was imported outside of `middleware.{js,ts}`.
## Possible Ways to Fix It
Only import and use `next/server` in a file located within the project root directory: `middleware.{js,ts}`.
```ts filename="middleware.ts"
import type { NextFetchEvent, NextRequest } from 'next/server'
export function middleware(req: NextRequest, ev: NextFetchEvent) {
return new Response('Hello, world!')
}
```
## Useful Links
- [Middleware](/docs/pages/building-your-application/routing/middleware)