Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dev": "BACKEND_PORT=${STACK_DEV_FALLBACK_BACKEND:+${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}10} && BACKEND_PORT=${BACKEND_PORT:-${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}02} && concurrently -n \"dev,codegen,prisma-studio,email-queue,cron-jobs,bulldozer-studio\" -k \"STACK_DISABLE_REACT_ASYNC_DEBUG_INFO=${STACK_DISABLE_REACT_ASYNC_DEBUG_INFO:-true} next dev --port $BACKEND_PORT ${STACK_BACKEND_DEV_EXTRA_ARGS:-}\" \"pnpm run codegen:watch\" \"pnpm run prisma-studio\" \"pnpm run run-email-queue\" \"pnpm run run-cron-jobs\" \"pnpm run run-bulldozer-studio\"",
"dev:inspect": "STACK_BACKEND_DEV_EXTRA_ARGS=\"--inspect\" pnpm run dev",
"dev:profile": "STACK_BACKEND_DEV_EXTRA_ARGS=\"--experimental-cpu-prof\" pnpm run dev",
"build": "pnpm run codegen && next build",
"build": "pnpm run codegen && next build && node scripts/patch-required-server-files.mjs",
"docker-build": "pnpm run codegen && next build --experimental-build-mode compile",
"build-self-host-migration-script": "tsdown --config scripts/db-migrations.tsdown.config.ts",
"analyze-bundle": "next experimental-analyze",
Expand Down
36 changes: 36 additions & 0 deletions apps/backend/scripts/patch-required-server-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Workaround for https://github.com/vercel/next.js/issues/91661
*
* Next.js 16.2 doesn't include `.next/package.json` (the CJS boundary marker)
* in the `required-server-files.json` manifest. Without it, Vercel's serverless
* functions inherit `"type": "module"` from the project's package.json, causing
* `require is not defined` at runtime.
*
* The upstream fix landed in vercel/next.js#93612 (canary only as of 16.2.6).
* This script patches the manifest after `next build` to include the file.
*
* Remove this script once we upgrade to a stable Next.js release containing the fix.
*/

import { readFileSync, writeFileSync, existsSync } from 'fs';
import { join } from 'path';

const distDir = '.next';
const manifestPath = join(distDir, 'required-server-files.json');

if (!existsSync(manifestPath)) {
// Not all build modes produce this manifest (e.g. compile-only docker builds)
process.exit(0);
}

const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));

const packageJsonEntry = join(distDir, 'package.json');

if (!manifest.files.includes(packageJsonEntry)) {
manifest.files.push(packageJsonEntry);
writeFileSync(manifestPath, JSON.stringify(manifest));
console.log(`Patched ${manifestPath}: added ${packageJsonEntry} to files array`);
} else {
console.log(`${manifestPath} already includes ${packageJsonEntry}, no patch needed`);
}
Loading