I’m trying to build a NextJS app locally. The app builds successfully on Vercel but does not build locally. I’ve tried to replicate the same conditions as on Vercel (e.g. make the same env vars available), but somehow can’t get the app to build.
Here’s the output:
root@9249b25664a4:/app/apps/web# dotenv -o ../../.env.local -- pnpm next build --debug --no-mangling --no-lint
⚠ Linting is disabled.
⚠ Mangling is disabled. Note: This may affect performance and should only be used for debugging purposes.
▲ Next.js 14.2.4
Creating an optimized production build ...
✓ Compiled successfully
✓ Checking validity of types
Collecting page data ..Error: Invariant failed
at i (/app/apps/web/.next/server/chunks/1164.js:4:122867)
at 70364 (/app/apps/web/.next/server/app/api/metrics/best/route.js:1:3568)
at t (/app/apps/web/.next/server/webpack-runtime.js:1:128)
at 68930 (/app/apps/web/.next/server/app/api/metrics/best/route.js:1:1355)
at t (/app/apps/web/.next/server/webpack-runtime.js:1:128)
at r (/app/apps/web/.next/server/app/api/metrics/best/route.js:1:6004)
at /app/apps/web/.next/server/app/api/metrics/best/route.js:1:6047
at t.X (/app/apps/web/.next/server/webpack-runtime.js:1:1206)
at /app/apps/web/.next/server/app/api/metrics/best/route.js:1:6017
at Object.<anonymous> (/app/apps/web/.next/server/app/api/metrics/best/route.js:1:6075)
Error: Invariant failed
at i (/app/apps/web/.next/server/chunks/1164.js:4:122867)
at 70364 (/app/apps/web/.next/server/app/api/metrics/reliability/route.js:1:2639)
at t (/app/apps/web/.next/server/webpack-runtime.js:1:128)
at 61279 (/app/apps/web/.next/server/app/api/metrics/reliability/route.js:1:1344)
at t (/app/apps/web/.next/server/webpack-runtime.js:1:128)
at r (/app/apps/web/.next/server/app/api/metrics/reliability/route.js:1:5075)
at /app/apps/web/.next/server/app/api/metrics/reliability/route.js:1:5113
at t.X (/app/apps/web/.next/server/webpack-runtime.js:1:1206)
at /app/apps/web/.next/server/app/api/metrics/reliability/route.js:1:5088
at Object.<anonymous> (/app/apps/web/.next/server/app/api/metrics/reliability/route.js:1:5141)
> Build error occurred
Error: Failed to collect page data for /api/metrics/best
at /app/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/build/utils.js:1268:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
type: 'Error'
}
Does anyone know why this happens? How can I get the actual error message out from Invariant failed (it seems like other occurrences of this error mentioned online are accompanied by additional details). Also, if it reruns the build command, it seems like the page fails to collect changes.
All of the following results in the same error:
turbo run build --env-mode=loose
dotenv -o ../../.env.local -- pnpm next build --debug --no-mangling --no-lint
dotenv -o ../../.env.local -- pnpm next build
pnpm next build
I expect the app to build like in Vercel.
Jeff An is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.