我正在尝试将 Next.js 应用程序部署到 Vercel,但遇到与特定 API 路由相关的构建错误。错误消息表明收集 /api/favourites/[driveSchoolId] 的页面数据失败,构建过程退出,代码为 1。以下是错误日志的相关部分:
错误信息:
at fa (/vercel/path0/node_modules/@prisma/client/runtime/library.js:33:69)
at new t (/vercel/path0/node_modules/@prisma/client/runtime/library.js:131:739)
at 13543 (/vercel/path0/.next/server/app/api/favourites/[drivingSchoolId]/route.js:1:3921)
at t (/vercel/path0/.next/server/webpack-runtime.js:1:128)
at 91782 (/vercel/path0/.next/server/app/api/favourites/[drivingSchoolId]/route.js:1:2942)
at t (/vercel/path0/.next/server/webpack-runtime.js:1:128)
at 40100 (/vercel/path0/.next/server/app/api/favourites/[drivingSchoolId]/route.js:1:1267)
at t (/vercel/path0/.next/server/webpack-runtime.js:1:128)
at t (/vercel/path0/.next/server/app/api/favourites/[drivingSchoolId]/route.js:1:4006)
at /vercel/path0/.next/server/app/api/favourites/[drivingSchoolId]/route.js:1:4041 {
clientVersion: '5.16.2',
errorCode: undefined
}
> Build error occurred
Error: Failed to collect page data for /api/favourites/[drivingSchoolId]
at /vercel/path0/node_modules/next/dist/build/utils.js:1268:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
type: 'Error'
}
Error: Command "npm run build" exited with 1
我也面临着完全相同的问题。我正在使用 Prisma 查询数据库,这就是 API 路由失败的原因。 如果您使用的是 prisma,请在 vercel 项目设置中更改构建命令,如下所示
npx prisma generate && next build