[builders] Fix import.meta.url missing when using CJS#1509
Conversation
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
🦋 Changeset detectedLatest commit: 880bdcd The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests🌍 Community Worlds (60 failed)mongodb (3 failed):
redis (2 failed):
turso (55 failed):
Details by Category✅ ▲ Vercel Production
✅ 💻 Local Development
✅ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
❌ 🌍 Community Worlds
✅ 📋 Other
|
📊 Benchmark Results
workflow with no steps💻 Local Development
▲ Production (Vercel)
workflow with 1 step💻 Local Development
▲ Production (Vercel)
workflow with 10 sequential steps💻 Local Development
▲ Production (Vercel)
workflow with 25 sequential steps💻 Local Development
▲ Production (Vercel)
workflow with 50 sequential steps💻 Local Development
▲ Production (Vercel)
Promise.all with 10 concurrent steps💻 Local Development
▲ Production (Vercel)
Promise.all with 25 concurrent steps💻 Local Development
▲ Production (Vercel)
Promise.all with 50 concurrent steps💻 Local Development
▲ Production (Vercel)
Promise.race with 10 concurrent steps💻 Local Development
▲ Production (Vercel)
Promise.race with 25 concurrent steps💻 Local Development
▲ Production (Vercel)
Promise.race with 50 concurrent steps💻 Local Development
▲ Production (Vercel)
workflow with 10 sequential data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
workflow with 25 sequential data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
workflow with 50 sequential data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
workflow with 10 concurrent data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
workflow with 25 concurrent data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
workflow with 50 concurrent data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
Stream Benchmarks (includes TTFB metrics)workflow with stream💻 Local Development
▲ Production (Vercel)
stream pipeline with 5 transform steps (1MB)💻 Local Development
▲ Production (Vercel)
10 parallel streams (1MB each)💻 Local Development
▲ Production (Vercel)
fan-out fan-in 10 streams (1MB each)💻 Local Development
▲ Production (Vercel)
SummaryFastest Framework by WorldWinner determined by most benchmark wins
Fastest World by FrameworkWinner determined by most benchmark wins
Column Definitions
Worlds:
❌ Some benchmark jobs failed:
Check the workflow run for details. |
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
karthikscale3
left a comment
There was a problem hiding this comment.
AI Review: Clean, well-gated fix for a real breakage (Prisma and anything using import.meta.url in CJS step bundles). The banner+define approach is the standard esbuild workaround, it's properly scoped to CJS-only, and test coverage is thorough at both build-output and runtime levels. Low risk — ship it.
I'd let @ijjk take a pass at this too.
TooTallNate
left a comment
There was a problem hiding this comment.
The polyfill is technically correct and well-tested. Approving as a reasonable stopgap given the discussion about moving the remaining CJS builders to ESM in parallel.
What I verified:
- The
pathToFileURL(__filename).hrefpolyfill forimport.meta.urlis the standard approach (same as ts-node, webpack). Cross-platform safe on Windows thanks topathToFileURLhandling drive letters and backslashes. - The
import.meta.resolvepolyfill viarequire.resolveis correct for common cases. Minor behavioral differences (CJS vs ESM resolution algorithm) are unlikely to matter in practice. - The
typeof __filename !== "undefined"guard is correct — prevents ReferenceError if the bundle somehow runs in ESM context, falls back toundefined. - No pre-existing
defineentries in any esbuild call — no risk of overwriting. - Banner concatenation is correct at both sites (step bundle already had trailing
\n, webhook bundle gets one added). - When
format !== 'cjs', the polyfill is a no-op (empty string banner, empty define object). - All
import.metausage in the codebase isimport.meta.urldirect property access — no destructuring or aliasing patterns that would escape esbuild'sdefine. - Test coverage is solid: e2e test validates
import.meta.urlis a defined string starting withfile://; local-build test verifies the polyfill variables appear in the CJS output and that rawimport.meta.urlis gone. - CI failures are benchmark-only (nextjs-turbopack), not related to this change.
Broader note: As discussed, this is treating a symptom — the root cause is that VercelBuildOutputAPIBuilder and StandaloneBuilder default createStepsBundle to CJS format. Every other builder already uses ESM. Migrating those two to ESM would eliminate the need for this polyfill entirely. I'd recommend tracking that as a follow-up.
One minor gap (non-blocking): The final workflow bundle (createWorkflowsBundle, ~line 827) can also be CJS for standalone/VBOA paths and doesn't get the polyfill. This is likely fine since the workflow VM sandbox doesn't support import.meta.url anyway, but worth noting for completeness.
|
|
||
| /** | ||
| * When outputting CJS, esbuild replaces `import.meta` with an empty object, | ||
| * making `import.meta.url` (and `import.meta.resolve`) undefined. This method |
There was a problem hiding this comment.
Non-blocking / follow-up: As we discussed, this polyfill is a reasonable stopgap for the Prisma + Vite user, but the cleaner long-term fix is migrating VercelBuildOutputAPIBuilder and StandaloneBuilder to output ESM instead of CJS. Every other builder already passes format: 'esm' to createStepsBundle. Once those two are migrated, this polyfill can be removed entirely.
Closes #1507