You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I traced the issue down to an import from the posgres package.
I was able to fix the issue by reorganizing my steps so that the function I imported from this package was only used in a step and not in a workflow.
The error message is quite confusing though, there's no context as to why this happened. For example, it would have been useful to see somewhere that this error occurred when evaluating in the workflow's context.
This still happens on workflow 4.8.1 (@workflow/builders 4.1.6, @workflow/swc-plugin 4.1.2). Could this be reopened? It took down every workflow in our production app, and the build gave no warning.
Minimal repro (Next.js + withWorkflow):
// workflows/steps.tsimportpgfrom'pg'// A non-step export keeps the `pg` import alive in the workflow bundleexportfunctionmakePool(){returnnewpg.Pool()}exportasyncfunctionmyStep(){'use step'return1}
next build / next typegen succeed with no workflow-node-module-error. At runtime, every workflow run fails when the bundle loads, including workflows that never touch steps.ts:
ReferenceError: require is not defined
Why it gets through: in workflow mode, the SWC transform replaces step bodies and removes unused code, but it keeps non-step exports and everything they reference. So makePool keeps pg in the bundle. pg is CommonJS, so esbuild emits require(...) calls, which the node:vm context can't run. The workflow-node-module-error check (after #1821) only looks at node:/bun: built-ins that survive into the bundle, so it never sees a require coming from inside an npm package. Removing the makePool export makes pg drop out of the bundle.
Suggestions, in order of impact:
Fail the build when the final workflow bundle still contains a CommonJS require call, and use the esbuild metafile to name the import chain that brought it in. This would have caught both this issue and our incident.
Document that non-step exports of a step file stay in the workflow bundle together with their imports. Today the docs describe the step placeholders but not this.
As a workaround, we now run a CI check that loads the generated flow-route bundle through runWorkflow from @workflow/core with a workflow name that doesn't exist. If it throws anything other than WorkflowNotRegisteredError, the bundle can't load. A public API for that ("evaluate the workflow bundle and report load errors") would let other users do the same without importing an internal file.
Activity
pensono commentedon Feb 22, 2026
I traced the issue down to an import from the
posgrespackage.I was able to fix the issue by reorganizing my steps so that the function I imported from this package was only used in a step and not in a workflow.
The error message is quite confusing though, there's no context as to why this happened. For example, it would have been useful to see somewhere that this error occurred when evaluating in the workflow's context.
Niapya commentedon Mar 4, 2026
same issues. I don't even know which step or which library caused the problem.
pensono commentedon Mar 5, 2026
Noting that this can happen if there's a bad import in any of the files any workflows, not just the one which you are trying to start.
VaguelySerious commentedon Apr 3, 2026
@pensono @Niapya Are you still seeing this on the latest version?
lra commentedon Sep 30, 2026
This still happens on
workflow4.8.1 (@workflow/builders4.1.6,@workflow/swc-plugin4.1.2). Could this be reopened? It took down every workflow in our production app, and the build gave no warning.Minimal repro (Next.js +
withWorkflow):next build/next typegensucceed with noworkflow-node-module-error. At runtime, every workflow run fails when the bundle loads, including workflows that never touchsteps.ts:Why it gets through: in workflow mode, the SWC transform replaces step bodies and removes unused code, but it keeps non-step exports and everything they reference. So
makePoolkeepspgin the bundle.pgis CommonJS, so esbuild emitsrequire(...)calls, which thenode:vmcontext can't run. Theworkflow-node-module-errorcheck (after #1821) only looks atnode:/bun:built-ins that survive into the bundle, so it never sees arequirecoming from inside an npm package. Removing themakePoolexport makespgdrop out of the bundle.Suggestions, in order of impact:
requirecall, and use the esbuild metafile to name the import chain that brought it in. This would have caught both this issue and our incident.As a workaround, we now run a CI check that loads the generated flow-route bundle through
runWorkflowfrom@workflow/corewith a workflow name that doesn't exist. If it throws anything other thanWorkflowNotRegisteredError, the bundle can't load. A public API for that ("evaluate the workflow bundle and report load errors") would let other users do the same without importing an internal file.VaguelySerious commentedon Sep 30, 2026
Linking to #4268
fix(builders): fail the build when the flow bundle still needs requir…