I don't know why I am getting this error during the production build like npm run build
My project structure is like below
project/
- src/
- app
- middleware.js
and the middleware file is like
export { default } from "next-auth/middleware";
export const config = {
matcher: ["/listings/my-listings", "/listings/new"],
};
And when I try to build it. I encounter the following error:
Error: next/server should not be imported outside of pages/_middleware.js. See: https://nextjs.org/docs/messages/no-server-import-in-page @next/next/no-server-import-in-page
Optionally my API route is like below
import { NextResponse } from "next/server";
import { getCurrentUser } from "@/actions/getCurrentUser";
export async function POST(request) {
const currentUser = await getCurrentUser();
if (!currentUser) {
return NextResponse.json(
{ message: "Authentication faild!" },
{ status: 401 }
);
}
return NextResponse.json("okay");
}
I don't understand what is the issue here.
Thanks