rsnext/errors/no-server-import-in-page.mdx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
628 B
Text
Raw Normal View History

---
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)