fix(rolldown): fix CJS require handling for nodeless worker builds#4019
fix(rolldown): fix CJS require handling for nodeless worker builds#4019medz wants to merge 1 commit intonitrojs:mainfrom
Conversation
|
@medz is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis PR introduces require-condition resolution for Rolldown in Nitro's build system. It adds a new plugin module that conditionally resolves CommonJS require calls based on export conditions, integrates it into the Rolldown configuration, and provides comprehensive unit tests for the new functionality. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/build/rolldown/config.ts (1)
52-57:⚠️ Potential issue | 🟡 MinorRemove debug
console.log— likely a leftover.Line 54 unconditionally logs
warning.codeto stdout on every rolldown warning. This looks like a debug artifact. Thewarn(warning)call on the next line already handles emitting the warning properly. Per coding guidelines, build code should useconsolaornitro.loggerfor logging.Proposed fix
onwarn(warning, warn) { if (!base.ignoreWarningCodes.has(warning.code || "")) { - console.log(warning.code); warn(warning); } },As per coding guidelines,
src/**/*.{js,ts}: "Useconsolafor logging in build/dev code; usenitro.loggerwhen available".
commit: |
🔗 Linked issue
#4010
❓ Type of change
📚 Description
This fixes the rolldown regression reported in #4010 for Cloudflare worker targets.
require-callto resolve package exports withrequire-first conditions (instead of accidentally selectingimportentries for CJS requires).esmExternalRequirePluginfor nodeless builds so Node builtins used via CJSrequire()are emitted as ESM-compatible externals for worker runtimes.import/require) resolution behavior.Validated with the minimal repro:
medz/nitro-issue-4010-pg-cloudflare-repro
NITRO_BUILDER=rolldown nitro build+wrangler devnow starts successfully and serves requests (norequire("events")startup failure).📝 Checklist