I encountered this error in the next js
TypeError: Cannot read property of undefined (read 'header') in eval (webpack-internal:///(sc_server)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:61)
Code snippet example:
newUser .save() .then(() => NextResponse.json({ msg: "Successfuly created new User: " + newUser ,status:200}) ) .catch((err: string) =>{ NextResponse.json({ error: "Error on '/api/register': " + err ,status:400}) } );
Tried multiple approaches like importing NextApiRequest
and NextApiResponse
and using it.
It has no status and JSON properties, basically it gives type error Property does not exist in NextApiResponse
.
So I used NextResponse
directly and still got this error.
I think you have to
return
NextResponse.json
.This is what may cause this error.