Skip to content

[builders] Use individual step imports for Next.js Turbopack compatibility#1698

Merged
VaguelySerious merged 4 commits into
peter/v2-flowfrom
peter/v2-flow-turbopack-fix
Apr 12, 2026
Merged

[builders] Use individual step imports for Next.js Turbopack compatibility#1698
VaguelySerious merged 4 commits into
peter/v2-flowfrom
peter/v2-flow-turbopack-fix

Conversation

@VaguelySerious
Copy link
Copy Markdown
Member

Summary

  • 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

Related: #1338

Test plan

  • pnpm vitest run packages/core/src/workflow.test.ts — 71 tests pass
  • pnpm vitest run packages/builders — 258/260 pass (2 pre-existing failures in node-module-esbuild-plugin.test.ts)
  • Stage with tarballs and run pnpm next build on workbench/nextjs-turbopack — Turbopack build succeeds
  • Verified generated route.js contains individual step imports instead of __step_registrations.js import

🤖 Generated with Claude Code

…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>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment Apr 11, 2026 10:14pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment Apr 11, 2026 10:14pm
example-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workbench-astro-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workbench-express-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workbench-fastify-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workbench-hono-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workbench-nitro-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workbench-nuxt-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workbench-sveltekit-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workbench-vite-workflow Ready Ready Preview, Comment Apr 11, 2026 10:14pm
workflow-docs Ready Ready Preview, Comment, Open in v0 Apr 11, 2026 10:14pm
workflow-swc-playground Ready Ready Preview, Comment Apr 11, 2026 10:14pm

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 11, 2026

🦋 Changeset detected

Latest commit: d082a0b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When 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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 11, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 771 0 219 990
❌ 💻 Local Development 708 57 315 1080
✅ 📦 Local Production 765 0 315 1080
✅ 🐘 Local Postgres 765 0 315 1080
✅ 🪟 Windows 82 0 8 90
✅ 📋 Other 171 0 99 270
Total 3262 57 1271 4590

❌ Failed Tests

💻 Local Development (57 failed)

fastify-stable (57 failed):

  • addTenWorkflow | wrun_01KNZ9QRJAK6Y8TP40NQFE1H4R
  • addTenWorkflow | wrun_01KNZ9QRJAK6Y8TP40NQFE1H4R
  • promiseAllWorkflow | wrun_01KNZ9QZ0WYHVQ62X6Z28ZBBA2
  • promiseRaceWorkflow | wrun_01KNZ9R482TY341QSMGYGXFBZ9
  • promiseAnyWorkflow | wrun_01KNZ9RG7DMX8E6DZ8GX6NE2G2
  • hookWorkflow | wrun_01KNZ9RX0DNRNXCCJK01D5PWW8
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01KNZ9S8Y6AMQ0TDQEA73VHA39
  • webhookWorkflow | wrun_01KNZ9SJ3ZH75KW15MR8BE1ZBV
  • webhook route with invalid token
  • sleepingWorkflow | wrun_01KNZ9SQA07V5ABSF0ZD0NYATJ
  • parallelSleepWorkflow | wrun_01KNZ9T46551TZR1DT1BDTKACF
  • nullByteWorkflow | wrun_01KNZ9T8YGWZMVBCJX5Y4TC2S0
  • workflowAndStepMetadataWorkflow | wrun_01KNZ9TBNR2TE5NQ11HRT3HM0S
  • fetchWorkflow | wrun_01KNZ9X2TX4DTWC15Q4ZTJV55E
  • promiseRaceStressTestWorkflow | wrun_01KNZ9X572DQ8WH7E336P6G2R8
  • error handling error propagation workflow errors nested function calls preserve message and stack trace
  • error handling error propagation workflow errors cross-file imports preserve message and stack trace
  • error handling error propagation step errors basic step error preserves message and stack trace
  • error handling error propagation step errors cross-file step error preserves message and function names in stack
  • error handling retry behavior regular Error retries until success
  • error handling retry behavior FatalError fails immediately without retries
  • error handling retry behavior RetryableError respects custom retryAfter delay
  • error handling retry behavior maxRetries=0 disables retries
  • error handling catchability FatalError can be caught and detected with FatalError.is()
  • error handling not registered WorkflowNotRegisteredError fails the run when workflow does not exist
  • error handling not registered StepNotRegisteredError fails the step but workflow can catch it
  • error handling not registered StepNotRegisteredError fails the run when not caught in workflow
  • stepDirectCallWorkflow - calling step functions directly outside workflow context
  • hookCleanupTestWorkflow - hook token reuse after workflow completion | wrun_01KNZA0SDSNDX72YQDKCDY289H
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01KNZA1FZGEGD9CRQ44SCYCZ5Z
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running | wrun_01KNZA21HYHH3HGTNNECER0R3E
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars) | wrun_01KNZA2HD7RJG6W7ZE07MGQGHG
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_01KNZA2TXP9B4TMJVRWBZJEY0A
  • closureVariableWorkflow - nested step functions with closure variables | wrun_01KNZA30RTP9638W7BM4ACSW71
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step | wrun_01KNZA340Z9QCTR8TFJ37PV9FJ
  • runClassSerializationWorkflow - Run instances serialize across workflow/step boundaries | wrun_01KNZA3FX9FB93GN1ECD5HACNH
  • health check endpoint (HTTP) - workflow endpoint responds to __health query parameter
  • health check (queue-based) - workflow endpoint responds to health check messages
  • health check (CLI) - workflow health command reports healthy endpoints
  • pathsAliasWorkflow - TypeScript path aliases resolve correctly | wrun_01KNZA3ZGMHBX282RZ8QNCQYPF
  • Calculator.calculate - static workflow method using static step methods from another class | wrun_01KNZA45EAHDTX94EWA3SQHK4N
  • AllInOneService.processNumber - static workflow method using sibling static step methods | wrun_01KNZA4BS0VX5PVD7F0B95SS0A
  • ChainableService.processWithThis - static step methods using this to reference the class | wrun_01KNZA4JR95GYT1CCYJC0GJPNZ
  • thisSerializationWorkflow - step function invoked with .call() and .apply() | wrun_01KNZA4RXYJMT0H2JA692D9MXB
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | wrun_01KNZA4Z0DMBPVKE7C23K6GZYS
  • instanceMethodStepWorkflow - instance methods with "use step" directive | wrun_01KNZA55YXEGMRENS96ANKRFP8
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context | wrun_01KNZA5FJ0AVJ1C25FVG698VA1
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument | wrun_01KNZA5PTGBWWWGHPXRXMMKPT0
  • cancelRun - cancelling a running workflow | wrun_01KNZA5WSDVYF2730HD7J25P2V
  • cancelRun via CLI - cancelling a running workflow | wrun_01KNZA66D87CM6KY9GJGAZS40S
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep | wrun_01KNZA6JTMD06FV9BBQYN91EHY
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration | wrun_01KNZA7982H76Y2DK34M54JES5
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control) | wrun_01KNZA7KVRW6T0VFDWM2712Q8X
  • importMetaUrlWorkflow - import.meta.url is available in step bundles | wrun_01KNZA7TF0644MXTQ68GYPVJC4
  • metadataFromHelperWorkflow - getWorkflowMetadata/getStepMetadata work from module-level helper (#1577) | wrun_01KNZA7WHJB0YR7KTMHY66526E
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01KNZA7YS30N5QCN2QRAYWBJN5
  • getterStepWorkflow - getter functions with "use step" directive | wrun_01KNZA81AH0VXDASB8Q1TP4T5R

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 64 0 26
✅ example 64 0 26
✅ express 64 0 26
✅ fastify 64 0 26
✅ hono 64 0 26
✅ nextjs-turbopack 88 0 2
✅ nextjs-webpack 88 0 2
✅ nitro 64 0 26
✅ nuxt 64 0 26
✅ sveltekit 83 0 7
✅ vite 64 0 26
❌ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 57 0 33
✅ express-stable 57 0 33
❌ fastify-stable 0 57 33
✅ hono-stable 57 0 33
✅ nextjs-turbopack-canary 63 0 27
✅ nextjs-turbopack-stable 82 0 8
✅ nextjs-webpack-canary 63 0 27
✅ nextjs-webpack-stable 82 0 8
✅ nitro-stable 57 0 33
✅ nuxt-stable 57 0 33
✅ sveltekit-stable 76 0 14
✅ vite-stable 57 0 33
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 57 0 33
✅ express-stable 57 0 33
✅ fastify-stable 57 0 33
✅ hono-stable 57 0 33
✅ nextjs-turbopack-canary 63 0 27
✅ nextjs-turbopack-stable 82 0 8
✅ nextjs-webpack-canary 63 0 27
✅ nextjs-webpack-stable 82 0 8
✅ nitro-stable 57 0 33
✅ nuxt-stable 57 0 33
✅ sveltekit-stable 76 0 14
✅ vite-stable 57 0 33
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 57 0 33
✅ express-stable 57 0 33
✅ fastify-stable 57 0 33
✅ hono-stable 57 0 33
✅ nextjs-turbopack-canary 63 0 27
✅ nextjs-turbopack-stable 82 0 8
✅ nextjs-webpack-canary 63 0 27
✅ nextjs-webpack-stable 82 0 8
✅ nitro-stable 57 0 33
✅ nuxt-stable 57 0 33
✅ sveltekit-stable 76 0 14
✅ vite-stable 57 0 33
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 82 0 8
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 57 0 33
✅ e2e-local-postgres-nest-stable 57 0 33
✅ e2e-local-prod-nest-stable 57 0 33

📋 View full workflow run


Some E2E test jobs failed:

  • Vercel Prod: success
  • Local Dev: failure
  • Local Prod: success
  • Local Postgres: success
  • Windows: success

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>
@VaguelySerious VaguelySerious force-pushed the peter/v2-flow-turbopack-fix branch from 29064bc to d89544c Compare April 11, 2026 18:24
@VaguelySerious VaguelySerious force-pushed the peter/v2-flow-turbopack-fix branch from d89544c to e723c6d Compare April 11, 2026 18:39
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant