Reputation: 65
I've got this error while using next-connect package.(i'm following a guy on youtube)
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;
Upvotes: 4
Views: 6546
Reputation: 41
Change below value
import {createRouter} from 'next-connect';
const router = createRouter();
export default router.handler();
Upvotes: 2
Reputation: 50228
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();
Upvotes: 7