错误类型错误:(0,next_connect__WEBPACK_IMPORTED_MODULE_0__.default)不是函数

rseugnpd  于 2023-06-05  发布在  Webpack
关注(0)|答案(2)|浏览(718)

我在使用next-connect包时遇到了这个错误。(我正在YouTube上关注一个家伙)

这是我代码

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;
muk1a3rh

muk1a3rh1#

next-connectv1.0.0是最近发布的,不向后兼容。您可以降级到以前的版本(npm install next-connect@0.12.1),或更改当前语法以匹配v1.0.0版本。

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();
x6h2sr28

x6h2sr282#

低于价值的变化
import {createRouter} from 'next-connect';
const router = createRouter();
return default router.handler();

相关问题