fix(deploy): externalize bare Node builtins + add createRequire banner for CJS compat - #242
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the bundle stager to leave bare Node builtins external for transitive CommonJS dependencies, adding a banner to define require in the ESM bundle and introducing a test to verify this behavior. Feedback on these changes suggests defining require conditionally on globalThis to prevent potential syntax errors from duplicate declarations, and simplifying the NODE_EXTERNALS array by removing redundant node: prefix mappings covered by the wildcard pattern.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| banner: { | ||
| js: [ | ||
| 'import { createRequire as __agentworkforceCreateRequire } from "node:module";', | ||
| 'const require = __agentworkforceCreateRequire(import.meta.url);' | ||
| ].join('\n') | ||
| }, |
There was a problem hiding this comment.
Declaring const require in the global/module scope via the banner can cause a syntax error (Identifier 'require' has already been declared) if the user's code or any bundled dependency already defines a top-level require variable (which is a common pattern when using createRequire in ESM).
Since esbuild prepends the banner as a raw string after bundling, it cannot rename conflicting variables in the bundled code to avoid this collision.
To prevent this, we can safely define require on globalThis if it is not already defined. This avoids any duplicate declaration errors while still making require available to esbuild's dynamic require helpers and bundled CommonJS dependencies.
| banner: { | |
| js: [ | |
| 'import { createRequire as __agentworkforceCreateRequire } from "node:module";', | |
| 'const require = __agentworkforceCreateRequire(import.meta.url);' | |
| ].join('\n') | |
| }, | |
| banner: { | |
| js: [ | |
| 'import { createRequire as __agentworkforceCreateRequire } from "node:module";', | |
| 'if (typeof globalThis.require === "undefined") {', | |
| ' globalThis.require = __agentworkforceCreateRequire(import.meta.url);', | |
| '}' | |
| ].join('\n') | |
| }, |
| const NODE_EXTERNALS = [ | ||
| ...builtinModules, | ||
| ...builtinModules.map((name) => `node:${name}`), | ||
| 'node:*' | ||
| ]; |
There was a problem hiding this comment.
…ed forms Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Bot review comment audit (checked at HEAD
|
|
Warning Review limit reached
More reviews will be available in 27 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
node:*for deploy agent bundlescreateRequire(import.meta.url)banner so bundled transitive CommonJS deps can resolve external builtins from ESMagent.bundle.mjscontaining a transitive CJSrequire("process")Validation
pnpm --filter @agentworkforce/persona-kit build && pnpm --filter @agentworkforce/deploy testThis fixes the startup crash seen in cloud deployments:
Dynamic require of "process" is not supported.