[builders] Use individual step imports for Next.js Turbopack compatibility#1698
Merged
Conversation
…atibility When bundleFinalOutput is false (Next.js builds), the combined flow route now imports each step file individually instead of the monolithic esbuild __step_registrations.js bundle. This prevents Turbopack NFT tracing errors caused by dynamic patterns (process.cwd(), dynamic world adapter imports) in the bundled file. The esbuild step bundle is still generated for bundleFinalOutput: true (standalone/BOA builders) and for manifest extraction. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
🦋 Changeset detectedLatest commit: d082a0b The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types 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 |
Contributor
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests💻 Local Development (57 failed)fastify-stable (57 failed):
Details by Category✅ ▲ Vercel Production
❌ 💻 Local Development
✅ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
✅ 📋 Other
❌ Some E2E test jobs failed:
Check the workflow run for details. |
… accessor Replace static getWorld() import in serialization.ts with a globalThis Symbol-based accessor. This breaks the serialization.ts → world.ts → world-local/world-vercel import chain, preventing esbuild from bundling world.ts (with process.cwd(), dynamic imports) into the step registrations. The step registrations bundle is imported by the V2 combined flow route, and Turbopack traces its dependencies. The world.ts code triggers NFT tracing errors (process.cwd() detected as filesystem operation). Updated writable-stream.test.ts to use setWorld() instead of vi.mock for getWorld, since serialization.ts no longer imports getWorld directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
29064bc to
d89544c
Compare
d89544c to
e723c6d
Compare
Introduce get-world-lazy.ts: a shared globalThis Symbol-based accessor that replaces the static getWorld import in serialization.ts, run.ts, helpers.ts, start.ts, and resume-hook.ts. This eliminates ALL static import paths from step code to world.ts, keeping the step registrations bundle small and free of process.cwd()/world-local/world-vercel code. Also fix shouldPreferSourceBackedPackagePath in the deferred builder to not prefer source-backed paths for tarball-installed packages in node_modules, preventing the full source tree from being bundled. Updated start.test.ts and step/writable-stream.test.ts to use setWorld() instead of vi.mock for getWorld. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bundleFinalOutputisfalse(Next.js builds), the combined flow route now imports each step file individually instead of the monolithic esbuild__step_registrations.jsbundleprocess.cwd(), dynamic world adapter imports) in the bundled filebundleFinalOutput: true(standalone/BOA builders) and for manifest extractionRelated: #1338
Test plan
pnpm vitest run packages/core/src/workflow.test.ts— 71 tests passpnpm vitest run packages/builders— 258/260 pass (2 pre-existing failures innode-module-esbuild-plugin.test.ts)pnpm next buildonworkbench/nextjs-turbopack— Turbopack build succeedsroute.jscontains individual step imports instead of__step_registrations.jsimport🤖 Generated with Claude Code