From 077bc1a8a255a016efe8d2df989971515cba59ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BA=BFt=20Tu=E1=BA=A5n?= Date: Mon, 24 Aug 2026 22:12:43 +0700 Subject: [PATCH] fix(compression): use pathToFileURL for workerUrl to prevent bundler resolution failure (#11364) Merged via consolidated batch validation. Fixes Webpack/Turbopack production build failure (Module not found: compressionWorker.js) by using pathToFileURL(join(...)) instead of new URL(..., import.meta.url), which static bundler scanning misidentifies as an asset import. --- changelog.d/fixes/compression-worker-bundler-resolve.md | 1 + open-sse/services/compression/compressionWorkerPool.ts | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelog.d/fixes/compression-worker-bundler-resolve.md diff --git a/changelog.d/fixes/compression-worker-bundler-resolve.md b/changelog.d/fixes/compression-worker-bundler-resolve.md new file mode 100644 index 0000000000..3a867303d6 --- /dev/null +++ b/changelog.d/fixes/compression-worker-bundler-resolve.md @@ -0,0 +1 @@ +- **fix(compression):** use `pathToFileURL` in `compressionWorkerPool` so bundlers (Webpack / Turbopack) do not attempt static asset resolution of missing `compressionWorker.js` during build diff --git a/open-sse/services/compression/compressionWorkerPool.ts b/open-sse/services/compression/compressionWorkerPool.ts index c3f0f839c1..109940a14d 100644 --- a/open-sse/services/compression/compressionWorkerPool.ts +++ b/open-sse/services/compression/compressionWorkerPool.ts @@ -1,6 +1,6 @@ import { existsSync } from "node:fs"; import { dirname, join } from "node:path"; -import { fileURLToPath } from "node:url"; +import { fileURLToPath, pathToFileURL } from "node:url"; import { Worker } from "node:worker_threads"; import type { CompressionResult } from "./types.ts"; import type { StackedCompressionStep } from "./strategySelector.ts"; @@ -17,9 +17,10 @@ function positiveInteger(value: string | undefined, fallback: number): number { function workerUrl(): URL { const dir = dirname(fileURLToPath(import.meta.url)); for (const name of ["compressionWorker.js", "compressionWorker.ts"]) { - if (existsSync(join(dir, name))) return new URL(name, import.meta.url); + const candidate = join(dir, name); + if (existsSync(candidate)) return pathToFileURL(candidate); } - return new URL("compressionWorker.js", import.meta.url); + return pathToFileURL(join(dir, "compressionWorker.js")); } function unchanged(body: Record): CompressionResult { return { body, compressed: false, stats: null };