Repository navigation
fix(build)!: remove custom moduleSideEffects config - #4164
Conversation
The `moduleSideEffects` function returned `false` for all modules not in a small allowlist, causing bundlers to drop side-effect-only imports like `import '@pothos/plugin-prisma'`. This broke plugin-pattern libraries that register themselves through side effects. For rolldown: return `true` only for user source files (rootDir, excluding node_modules) so libraries with `sideEffects: false` in package.json still get tree-shaken while user code side effects are preserved. For rollup: use `moduleSideEffects: true` since `@rollup/plugin-node-resolve` handles package.json sideEffects at a higher precedence level. Also drops the `moduleSideEffects` config option (breaking change) as the new logic no longer needs a user-configurable allowlist. Closes #4085
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRemoved Nitro's Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 4
🧹 Nitpick comments (1)
test/vite/side-effects-fixture/server.ts (1)
1-2: Broaden this fixture to cover package/workspace side-effect imports.This only proves that a relative source-file import survives bundling. The regression in
#4085also involved side-effect-only package/workspace imports, so this fixture can still pass while the original failure remains untested.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/vite/side-effects-fixture/server.ts` around lines 1 - 2, The fixture only imports a relative source-file side-effect; add side-effect-only imports that simulate package/workspace modules to cover the regression: add imports for a published-package style module (e.g. import "example-package/register";) and a workspace-scoped module (e.g. import "@workspace/example/register";) alongside the existing "./server/utils/register-items.ts" import, and ensure the test still references getItems to assert the side-effects ran; update any mock/package entries in the fixture setup so those module specifiers resolve during bundling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/build/rolldown/config.ts`:
- Around line 42-44: The moduleSideEffects check currently only treats files
under nitro.options.rootDir as side-effectful, missing workspace-local packages;
update the moduleSideEffects function to return true when id startsWith either
nitro.options.rootDir or the resolved workspaceDir and still exclude paths that
match NODE_MODULES_RE (i.e., use startsWith(rootDir) || startsWith(workspaceDir)
&& !NODE_MODULES_RE.test(id)); reference the moduleSideEffects function,
nitro.options.rootDir, workspaceDir, and NODE_MODULES_RE when making the change.
In `@src/build/vite/bundler.ts`:
- Around line 43-47: The treeshake.moduleSideEffects function currently uses a
simple id.startsWith(nitro.options.rootDir) check which misclassifies sibling
workspace packages as side-effect-free; replace that rootDir-only heuristic with
the same workspace-aware predicate used elsewhere in the build (i.e., reuse the
workspace-aware module/source check the Rollup config uses) so
moduleSideEffects(id: string) returns the correct boolean for files inside
sibling workspace packages while still excluding "/node_modules/". Update the
moduleSideEffects implementation to call that shared predicate (or import it)
instead of id.startsWith(nitro.options.rootDir).
In `@test/vite/side-effects.test.ts`:
- Around line 13-37: The test "preserves side-effect imports" relies on the
shared mutable variable outDir being set in the separate "build" test, making
order-dependent and brittle tests; move the build/setup logic into a test
scaffold (e.g., beforeAll or beforeEach) so outDir is initialized and the Nitro
build is created regardless of test ordering: call createNitro(...) with rootDir
fixtureDir, output.dir = outDir (derived from tmpDir and builder), then await
prepare(nitro) and await build(nitro) inside the setup hook and remove the
standalone "build" test (or keep it as a no-op), ensuring the tests that
reference outDir (the "preserves side-effect imports" case that imports
server/index.mjs and calls the exported fetch) are decoupled from test execution
order; reference variables/functions: outDir, tmpDir, builder, fixtureDir,
createNitro, prepare, build, and the "preserves side-effect imports" test.
- Around line 1-2: The test currently uses a raw filesystem path (with
fileURLToPath imported) for a dynamic import which breaks on Windows; replace
that approach by importing pathToFileURL from "node:url", convert the built
entry filesystem path to a file:// URL using pathToFileURL(...) and pass that
URL (or its href) into the dynamic import() call so the test imports the module
cross-platform; update any places referencing fileURLToPath or the raw path to
use pathToFileURL before calling import().
---
Nitpick comments:
In `@test/vite/side-effects-fixture/server.ts`:
- Around line 1-2: The fixture only imports a relative source-file side-effect;
add side-effect-only imports that simulate package/workspace modules to cover
the regression: add imports for a published-package style module (e.g. import
"example-package/register";) and a workspace-scoped module (e.g. import
"@workspace/example/register";) alongside the existing
"./server/utils/register-items.ts" import, and ensure the test still references
getItems to assert the side-effects ran; update any mock/package entries in the
fixture setup so those module specifiers resolve during bundling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 40d27e60-1398-4bbe-a363-3e3f1a61c54f
📒 Files selected for processing (12)
docs/3.config/0.index.mdsrc/build/rolldown/config.tssrc/build/rollup/config.tssrc/build/vite/bundler.tssrc/config/defaults.tssrc/types/config.tstest/vite/side-effects-fixture/nitro.config.tstest/vite/side-effects-fixture/server.tstest/vite/side-effects-fixture/server/utils/register-items.tstest/vite/side-effects-fixture/server/utils/registry.tstest/vite/side-effects-fixture/vite.config.tstest/vite/side-effects.test.ts
💤 Files with no reviewable changes (3)
- docs/3.config/0.index.md
- src/config/defaults.ts
- src/types/config.ts
moduleSideEffects config
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@examples/vite-ssr-vue-router/vite.config.mjs`:
- Line 11: The example config currently forces Nitro's
rollupOptions.treeshake.moduleSideEffects to () => false which reintroduces the
side-effect tree-shaking regression; remove this override from the nitro
configuration (the rollupOptions -> treeshake -> moduleSideEffects entry) so the
example relies on the bundler's default behavior (i.e., delete that
moduleSideEffects line or stop setting moduleSideEffects entirely).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 38a5fb60-2286-426a-9e5a-7a7cc3a9f46a
📒 Files selected for processing (3)
docs/4.examples/vite-ssr-vue-router.mdexamples/vite-ssr-vue-router/vite.config.mjstest/examples.test.ts
Nitro 2.13.4 leaves side-effect-only `import "node:*"` statements in dist/_worker.js, which Cloudflare Pages' deploy esbuild warns about as ignored-bare-import (unenv polyfills declare sideEffects:false). After compile, strip only bare node: imports and leave named from "node:*" imports that nitropack needs. Mirrors the not-yet-released approach in nitrojs/nitro#4164 for cloudflare-pages.
# [1.56.0](v1.55.7...v1.56.0) (2026-07-12) ### Bug Fixes * **config:** address production-readiness review findings ([3af3b2c](3af3b2c)) * **config:** avoid CodeQL TOCTOU findings in CF worker postprocess ([921155d](921155d)) * **config:** declare empty preview APP_URL and analytics vars ([3c66b51](3c66b51)) * **ci:** harden link check and drop bogus changelog issue refs ([959c35e](959c35e)), closes [hi#cardinality](https://github.com/hi/issues/cardinality) * **config:** quiet production build noise from sitemap runtime path ([e3a03a1](e3a03a1)) * **config:** strip bare node: side-effect imports from CF worker ([2725338](2725338)), closes [nitrojs/nitro#4164](nitrojs/nitro#4164) * **config:** type readdir Dirent as utf8 string names ([480a563](480a563)) ### Features * **api:** harden rate limiting with per-IP backstop, token cap, and 429 observability ([#523](#523)) ([b34c04d](b34c04d)), closes [hi#cardinality](https://github.com/hi/issues/cardinality)
…#3284) Fixes two stale references. No behavior change. - `packages/junior/src/build/rolldown-workarounds.ts`: replace the placeholder `nitrojs/nitro/issues/XXXX` link with the real issue, nitrojs/nitro#4085. The TODO now names an owner and a removal condition, per `policies/code-comments.md`. nitrojs/nitro#4164 removed the allowlist upstream, and the oldest Nitro version that Junior supports (`3.0.260415-beta`) includes that fix. So the override can probably go, but this PR does not remove it. That needs a production build check that pi-ai providers still register without it. - `.agents/skills/vercel-sandbox/SOURCES.md`: #1567 removed `chat/runtime/reply-executor.ts`. The row now points at `chat/providers/slack/turn.ts` and `chat/task-execution/conversation-turn.ts`, which save each new sandbox ref through `onSandboxRefChanged`. This matches `SKILL.md` and `references/api-surface.md`. The old "success-path only" description was also stale, so it is replaced. <!-- junior-request-attribution:start --> via @MathurAditya724. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A1704862f6367434a6de8ff84bf6d5be1 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A1704862f6367434a6de8ff84bf6d5be1) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A1704862f6367434a6de8ff84bf6d5be1/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Aditya Mathur <[email protected]>
Summary
Fixes #4085
Nitro's custom
treeshake.moduleSideEffectsfunction returnedfalsefor all modules not in a small allowlist (["unenv/polyfill/"]), overriding the bundler default and causing aggressive tree-shaking that removed side-effect-only imports (e.g.import '@pothos/plugin-prisma'). Dev mode worked fine but production builds broke.Changes
treeshake.moduleSideEffectsoverride from all bundler configs (rolldown, rollup, vite) — bundlers now use their defaults which correctly preserve side-effect importsmoduleSideEffectsconfig option from types, defaults, and docs (breaking change — the option was the root cause of the bug)test/vite/side-effects.test.ts) that builds across rolldown/rollup/vite and verifies side-effect imports are preservednode:side-effect imports in Cloudflare presets — addedstripBareNodeImports()output plugin that removes no-opimport "node:buffer"etc. from generated chunks. These bare imports are hoisted by the bundler during code-splitting and cause issues on worker runtimes. Applied to bothcloudflare-pagesandcloudflare-modulepresets.moduleSideEffects: () => falsein nitro environment configBreaking changes
moduleSideEffectsconfig option has been removed. Users who relied on it for marking modules with side effects no longer need it — bundlers now respect side-effect imports by default. Users can still userolldownConfig.treeshake.moduleSideEffectsorrollupConfig.treeshake.moduleSideEffectsdirectly for advanced use cases.Test plan
pnpm vitest run test/vite/side-effects.test.ts— regression test across rolldown/rollup/vitepnpm vitest run test/minimal/minimal.test.ts— bundle sizes verifiedpnpm vitest run test/presets/node.test.ts— no regressionspnpm vitest run test/presets/cloudflare-pages.test.ts— cloudflare bare node: imports stripped, all tests passpnpm format && pnpm typecheck— clean🤖 Generated with Claude Code