fix(nest): stop declaring require twice in the CommonJS steps bundle - #4144
Open
torsello wants to merge 2 commits into
Open
fix(nest): stop declaring require twice in the CommonJS steps bundle#4144torsello wants to merge 2 commits into
torsello wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: f22da80 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 |
Contributor
|
@torsello is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
`#rewriteStepsBundleForCjs` prepended its own `const require = __bundled_createRequire(...)` shim, but `createStepsBundle` already emits an ESM interop banner declaring `var require = __createRequire(...)`. Nest passes `bundleFinalOutput: false`, so `skipEsmRequireBanner` stays false and the banner is always present. Both statements declare `require` in one module scope, so the bundle throws `SyntaxError: Identifier 'require' has already been declared`. The build still reports success, so the failure surfaces later and indirectly: the flow route answers 500 and the run stays pending. The shim is redundant — the banner provides the same binding, plus `__filename` and `__dirname` — so drop it. Skipping the banner instead would remove those two and is explicitly warned against in `createStepsBundle`. Fixes vercel#3778 Signed-off-by: Matias Torsello <23641125+torsello@users.noreply.github.com>
torsello
force-pushed
the
fix/nest-cjs-duplicate-require
branch
from
September 12, 2026 11:38
a1fe769 to
9d0409c
Compare
Contributor
Author
|
@vercel/workflow ready for review |
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.
Description
Fixes #3778.
workflow-nest build --module commonjswrites a steps bundle that declaresrequiretwice, so importing it throwsSyntaxError: Identifier 'require' has already been declared. The build reports success, so the failure surfaces later and indirectly — the flow route answers 500 and the run stayspending.#rewriteStepsBundleForCjsprepends its owncreateRequireshim, butcreateStepsBundlealready emits an ESM interop banner declaring the same binding. Nest passesbundleFinalOutput: false, soskipEsmRequireBannerstaysfalseand the banner is always there.The shim is redundant, so this drops it. Skipping the banner instead — the fix the issue suggests — would also drop
__filename/__dirname, whichcreateStepsBundleexplicitly warns against in its JSDoc.How did you test your changes?
Built
workbench/nestwith--module commonjs, before and after.Before — build succeeds, bundle does not parse:
After — one declaration, parses clean:
__filename/__dirnameare still shimmed, since the banner is the one providing them.Importing the bundle in this workbench then fails on
MODULE_NOT_FOUNDfor../../example/workflows/*.js— those live outside the app'ssrc/, so they never land in itsdist/. That is the shared-workbench layout, unrelated to this change; without the fix the bundle never parses far enough to attempt resolution at all.pnpm --filter @workflow/nest testpasses (35 tests),biome checkis clean on the touched file.