Skip to content

Open source CapCut alternative.

TypeScript

fix(site): stub the Cut engine on hosted builds so /api/cut fits Vercel's size limit

David Le8cac8d465b36
diff --git a/site/next.config.ts b/site/next.config.ts
index 88e96bae..5dafc69d 100644
--- a/site/next.config.ts
+++ b/site/next.config.ts
@@ -13,14 +13,22 @@ const nextConfig: NextConfig = {
serverActions: { bodySizeLimit: "4gb" },
proxyClientMaxBodySize: "4gb",
},
- // Cut is local-only, so /api/cut/* 404s on a hosted deploy and never spawns the
- // Claude Agent SDK. Its platform CLI binary (~220MB, and unusable on Vercel's
- // runtime anyway) otherwise gets traced into the function and blows past
- // Vercel's 250MB limit. Drop the whole SDK binary family from every function's
- // trace; the /api/cut route returns 404 before the SDK is ever imported.
- outputFileTracingExcludes: {
- "/*": ["./node_modules/@anthropic-ai/claude-agent-sdk-*/**/*"],
- },
+ // Cut is local-only: /api/cut/* 404s on a hosted deploy and never runs the
+ // engine. But Turbopack's file tracer still follows the route's import of the
+ // engine router, and that graph reaches cwd-rooted file operations it can't
+ // statically scope — so it sweeps local media, committed stock video, and the
+ // ~220MB Claude Agent SDK CLI binary into the serverless function, past
+ // Vercel's 250MB limit. (outputFileTracingExcludes can't help: it's a no-op
+ // under Turbopack builds.) On hosted builds only, alias the engine entry to a
+ // 404 stub so the engine graph is never traced; local builds keep the real
+ // router, so `next dev`/`next start` serve Cut normally.
+ turbopack: process.env.VERCEL
+ ? {
+ resolveAlias: {
+ "@/cut/server/http/next": "./src/cut/server/http/hosted-stub.ts",
+ },
+ }
+ : undefined,
};
const withMDX = createMDX({
diff --git a/site/src/app/api/cut/[[...slug]]/route.ts b/site/src/app/api/cut/[[...slug]]/route.ts
index de19c705..5f1fddc4 100644
--- a/site/src/app/api/cut/[[...slug]]/route.ts
+++ b/site/src/app/api/cut/[[...slug]]/route.ts
@@ -4,10 +4,12 @@ import { isHostedRuntime } from "@/cut/server/local-only";
// (src/cut/server/http/routes.ts) — the same one the packaged engine mounts.
//
// Cut is local-only: on a hosted deploy every Cut API 404s. The 404 is returned
-// here, before the dynamic import that pulls the router, so the engine's module
-// graph — including the ~220MB Claude Agent SDK CLI binary that ai.ts imports —
-// never loads on hosted. next.config's outputFileTracingExcludes then drops that
-// binary from the deployed function so it fits Vercel's size limit.
+// here, before the dynamic import that pulls the router, so the engine never
+// runs on hosted. Turbopack still *traces* that import, though, and the engine's
+// module graph reaches cwd-rooted file operations it can't statically scope — so
+// on hosted builds next.config aliases "@/cut/server/http/next" to a 404 stub,
+// keeping the engine (and the ~220MB SDK CLI binary it would otherwise sweep in)
+// out of the deployed function so it fits Vercel's size limit.
export const runtime = "nodejs";
async function handle(req: Request): Promise<Response> {
diff --git a/site/src/cut/server/http/hosted-stub.ts b/site/src/cut/server/http/hosted-stub.ts
new file mode 100644
index 00000000..c396a762
--- /dev/null
+++ b/site/src/cut/server/http/hosted-stub.ts
@@ -0,0 +1,10 @@
+// On a hosted build, next.config.ts aliases "@/cut/server/http/next" to this
+// stub (gated on process.env.VERCEL). Cut is local-only: every Cut API 404s on
+// hosted, so the real engine router never needs to load there. Aliasing it away
+// keeps its module graph — including the cwd-rooted file operations Turbopack's
+// tracer would otherwise follow, sweeping local media, stock video, and the
+// ~220MB Claude Agent SDK CLI binary into the serverless function — out of the
+// deployed /api/cut function so it fits Vercel's size limit.
+export async function cutCatchAll(): Promise<Response> {
+ return new Response(null, { status: 404 });
+}