diff --git a/src/app/v1/[...route]/route.ts b/src/app/v1/[...route]/route.ts index 3a3c82922..88651c055 100644 --- a/src/app/v1/[...route]/route.ts +++ b/src/app/v1/[...route]/route.ts @@ -1,4 +1,5 @@ import "@/lib/polyfills/file"; +import "@/lib/polyfills/worker-threads"; import { Hono } from "hono"; import { handle } from "hono/vercel"; import { registerCors } from "@/app/v1/_lib/cors"; diff --git a/src/app/v1beta/[...route]/route.ts b/src/app/v1beta/[...route]/route.ts index 2c70283fe..b1f2f16a1 100644 --- a/src/app/v1beta/[...route]/route.ts +++ b/src/app/v1beta/[...route]/route.ts @@ -1,4 +1,5 @@ import "@/lib/polyfills/file"; +import "@/lib/polyfills/worker-threads"; import { Hono } from "hono"; import { handle } from "hono/vercel"; import { registerCors } from "@/app/v1/_lib/cors"; diff --git a/src/lib/polyfills/worker-threads.ts b/src/lib/polyfills/worker-threads.ts new file mode 100644 index 000000000..e1162726e --- /dev/null +++ b/src/lib/polyfills/worker-threads.ts @@ -0,0 +1,13 @@ +import { createRequire } from "node:module"; + +const nodeRequire = createRequire(import.meta.url); +const workerThreads = nodeRequire("node:worker_threads") as { + markAsUncloneable?: (...args: unknown[]) => void; +}; + +// undici >= 8 destructures markAsUncloneable from node:worker_threads without +// a fallback. Bun (Docker build stage) does not implement this Node.js 23+ API, +// so next build crashes during page data collection. +if (typeof workerThreads.markAsUncloneable !== "function") { + workerThreads.markAsUncloneable = function markAsUncloneable() {}; +}