我刚刚去vercel部署一个nextjs项目,遇到了这个错误:
> Build error occurred
Error: Failed to collect page data for /api/auth/[...nextauth]
at /vercel/path0/node_modules/next/dist/build/utils.js:1258:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
type: 'Error'
}
Error: Command "npm run build" exited with 1
这最初发生在我的 /api/auth/[...next-auth] 路线中,但我删除了该文件以查看是否是问题所在。 /app/api 目录中的每个文件都一一出错。
我尝试按照与此相关的另一篇文章添加以下内容:
export const dynamic = "force-dynamic";
export const fetchCache = "force-no-store";
但这没有用。我看到另一个解决方案说升级到节点 16,但我运行的是 20,这也没有解决问题。
本地构建没有失败,我以前也从未遇到过这个问题。
我不确定它是否与 next-auth 相关,但route.ts 文件如下所示:
import NextAuth from "next-auth";
import { NextRequest } from "next/server";
import { authOptions } from "@/lib/authOptions";
import { RouteHandlerContext } from "@/types/authTypes";
const auth = async (req: NextRequest, context: RouteHandlerContext) => {
return await NextAuth(req, context, authOptions(context));
}
export { auth as GET, auth as POST };
我还已经有了 NEXTAUTH_URL 和 NEXTAUTH_SECRET 的环境变量。
我也没有收到应用程序路由器中任何页面的错误,似乎只有 /api 中找到的错误。
谢谢
嗯..对于将来遇到此问题的任何人:
我首先更新了 package.json 文件以在构建时运行 prisma 命令:
"scripts": {
"dev": "next dev",
"build": "prisma generate && next build",
"start": "next start",
"lint": "next lint"
},
其次,在创建项目时,在将其移动到存储库的根目录后,我忘记删除使用 create-next-app 为项目创建的默认文件夹。这是主要问题,但是 prisma 在构建过程中也会抛出错误。