Files
next.js/errors/no-server-import-in-page.mdx
bc59f210b0 docs: Deprecation of Middleware (#84710)
This PR removes middleware docs and adds a "Migration to Proxy" section
to the Proxy docs, which explains the rationale for the renaming to
Proxy and provides a migration guide.

Did not remove `middleware-upgrade-docs` as it's an upgrade doc from the
legacy middleware.

Below are untouched as they need codebase changes:

- `instrumentation` docs - `onRequestError` has `context.routeType` as
`'middleware'`
- `adapterPath` docs - has `MiddlewareMatcher` type example
- `ProxyConfig` - has a user-facing `MiddlewareMatcher` type

---------

Co-authored-by: Joseph Chamochumbi <[email protected]>
2025-10-17 20:03:13 +02:00

26 lines
590 B
Plaintext

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