Back to Next Js

No Server Import In Page

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

16.2.5548 B
Original Source

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
import type { NextFetchEvent, NextRequest } from 'next/server'

export function proxy(req: NextRequest, ev: NextFetchEvent) {
  return new Response('Hello, world!')
}