Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Error TypeError: (0 , next_connect__WEBPACK_IMPORTED_MODULE_0__.default) is not a function

I've got this error while using next-connect package.(i'm following a guy on youtube)

enter image description here

here's my code

import nc from 'next-connect';
import Product from '../../../models/Product';
import db from '../../../utils/db';

const handler = nc();

handler.get(async (req, res) => {
  await db.connect();
  const products = await Product.find({});
  await db.disconnect();
  res.send(products);
});

export default handler;
like image 831
wail Avatar asked Oct 31 '25 17:10

wail


1 Answers

next-connect v1.0.0 was recently released and is not backward-compatible. You can either downgrade to a previous version (npm install [email protected]), or change your current syntax to match the v1.0.0 version.

import { createRouter } from 'next-connect';
import Product from '../../../models/Product';
import db from '../../../utils/db';

const router = createRouter();

router.get(async (req, res) => {
    await db.connect();
    const products = await Product.find({});
    await db.disconnect();
    res.send(products);
});

export default router.handler();
like image 65
juliomalves Avatar answered Nov 02 '25 07:11

juliomalves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!