Background
In my development environment, I am using NextJS v11.1.1-canary.11
, React v17.0.2
, and Typescript v4.3.5
.
To set up a basic API endpoint following the guidelines from NextJS Typescript documentation, I created a file named login.tsx
in the pages/proxy
folder with a simple API code snippet:
import type { NextApiRequest, NextApiResponse } from 'next'
export default function Login(req: NextApiRequest, res: NextApiResponse) {
res.status(200).json({ name: 'John Doe' })
}
The Issue
Upon calling the API endpoint, an error is triggered :
TypeError: res.status is not a function
at Login (C:\wamp64\www\project-front\.next\server\pages\proxy\login.js:19:7)
You can find the full stacktrace here.
Despite researching extensively, I have been unable to locate any similar cases on Google or Stackoverflow. As a newcomer to NextJS, it's possible that I am overlooking something. Is there anyone who might have insights into what I may be doing incorrectly?