No HTTP methods exported in '…'. Export a named export for each HTTP method – Javascript

by
Ali Hasan
next.js react-typescript reactjs

Quick Fix: Export HTTP methods as named exports, like export async function GET(req, res) {}, export async function POST(req, res) {}, etc.

The Solutions:

Solution 2: Establish HTTP Method Functions As Named Exports

In API Route Handlers, HTTP method functions should adhere to the syntax:

export async function METHOD() {}

Replace your original postHandler function with this:

export async function POST(req: NextApiRequest, res: NextApiResponse) {
  // Your existing POST request handler code
}

Ensure that corresponding HTTP methods (e.g., GET, PUT) are similarly defined as named exports in the API Route Handler file.

Video Explanation:

The following video, titled "NextJs 13 API routes in `app` folder | NextJs 13 series - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

In this video, we'll look at the new route handlers in the app folder, replacing the API routes in the pages directory.