hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.63k stars 65 forks source link

Bug: TypeError Trouter is not a constructor #116

Closed artismarti closed 3 years ago

artismarti commented 3 years ago

I'm able to get the right responses in the browser:

image

when I navigate to the api /api/coffee.js with the following code:

import nextConnect from "next-connect";

export default nextConnect()
  .get(async (req, res) => {
    res.statusCode = 200;
    res.json({
      "Hello": "World"
    });
  })

However when I go to the home page I get this error:

image

The stack trace points to this line of code: const router = new Trouter();

Any help with this is massively appreciated. Thank you! :)

artismarti commented 3 years ago

I think this was because I had imported the api file in my index.js file. Once I removed the import, this error disappeared.