When I am trying to build a Next.Js project with MongoDB, it complains:
GET /api/user 500 in 14ms
⨯ pages/api/user/index.js (12:20) @ ncOpts
⨯ TypeError: (0 , next_connect__WEBPACK_IMPORTED_MODULE_8__.default) is not a function
at eval (webpack-internal:///(api)/./pages/api/user/index.js:32:73)
10 |
11 | const upload = multer({ dest: '/tmp' });
> 12 | const handler = nc(ncOpts);
| ^
13 |
14 | if (process.env.CLOUDINARY_URL) {
15 | const {
GET /api/user 500 in 8ms
One code snippet is as follows:
import { findUserById } from '@/api-lib/db';
import { getMongoDb } from '@/api-lib/mongodb';
import { ncOpts } from '@/api-lib/nc';
import nc from 'next-connect';
const handler = nc(ncOpts);
handler.get(async (req, res) => {
const db = await getMongoDb();
const user = await findUserById(db, req.query.userId);
res.json({ user });
});
export default handler;
Package versions are as follows:
"next": "^14.2.5",
"next-connect": "^1.0.0",
"mongodb": "^6.8.0",
At first, I have no clean what this error mean.
The problem was caused by version upgrade. The sample was using "next-connect": "^0.12.2"