Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-next-build-stale-socket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@workflow/next": patch
---

fix(next): guard socket-info filesystem fallback behind lazy discovery flag

Prevents `ECONNREFUSED` during `next build` when a stale `workflow-socket.json` file exists from a previous `next dev` session.
7 changes: 7 additions & 0 deletions .changeset/fix-step-bundle-dynamic-imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@workflow/builders": patch
---

fix(builders): add `webpackIgnore` comments to dynamic imports in generated step bundle

Prevents Turbopack/webpack "Module not found" errors for runtime-resolved dynamic `import()` calls (e.g. from `@vercel/queue`) that are inlined into the step route bundle.
16 changes: 16 additions & 0 deletions packages/builders/src/base-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,22 @@ export abstract class BaseBuilder {

const stepsResult = await esbuildCtx.rebuild();

// Post-process the generated step bundle to add bundler-ignore comments
// to dynamic `import()` calls with non-literal arguments (e.g. variables,
// expressions). These dynamic imports are resolved at runtime and should
// not be traced by downstream bundlers like Turbopack/webpack, which would
// otherwise emit "Module not found" errors for unresolvable paths.
if (outfile) {
const bundleContent = await readFile(outfile, 'utf8');
const processed = bundleContent.replace(
/\bimport\((?!\s*["'`])/g,
'import(/* webpackIgnore: true */ '
);
if (processed !== bundleContent) {
await writeFile(outfile, processed);
}
}

this.logEsbuildMessages(stepsResult, 'steps bundle creation');
this.logBaseBuilderInfo(
'Created steps bundle',
Expand Down
8 changes: 8 additions & 0 deletions packages/next/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ function getSocketInfoFilePath(): string | null {
return configuredPath;
}

// Only fall back to filesystem discovery when deferred (lazy) discovery is
// active. Without this guard, a stale socket-info file left behind by a
// previous `next dev` session causes ECONNREFUSED during eager builds
// (i.e. `next build` without `lazyDiscovery`).
if (process.env.WORKFLOW_NEXT_LAZY_DISCOVERY !== '1') {
return null;
}

// Fallback for worker processes that don't inherit dynamic env updates
// from the process that created the socket server.
const distDir = process.env.WORKFLOW_NEXT_DIST_DIR || '.next';
Expand Down
Loading