Skip to content

Fix the CommonJS entry point of @fedify/nestjs - #1428

Merged
dahlia merged 1 commit into
fedify-dev:2.0-maintenancefrom
dahlia:bugfix/nestjs-require
Nov 14, 2026
Merged

dahlia merged 1 commit into
fedify-dev:2.0-maintenancefrom
dahlia:bugfix/nestjs-require

Conversation

@dahlia

@dahlia dahlia commented Nov 12, 2026

Copy link
Copy Markdown
Member

require("@fedify/nestjs") fails with MODULE_NOT_FOUND because the package manifest points its CommonJS entry point and declarations at dist/index.js and dist/index.d.ts, which the build no longer emits. NestJS projects compile to CommonJS by default, so this is the usual way to load the integration; ESM imports are not affected.

The build's output file names changed in a05a6b9, which upgraded tsdown to 0.21. With platform: "node", tsdown 0.21 enables fixedExtension by default and emits dist/index.cjs and dist/index.d.cts for the CommonJS build. That commit added outExtensions hooks to the other packages to keep their output matching their manifests, but missed packages/nestjs. It was merged forward from 1.9-maintenance, so the bug first shipped in 1.9.7 and reached 2.0.9 and 2.1.2 the same way. After building this branch, I checked every published package's main, module, types, and exports targets against the files on disk; only these four nestjs entries were missing.

This updates main, types, and exports["."].require to point to the files the build produces, as #1424 proposes. I considered restoring the old .js/.d.ts names with outExtensions instead. I kept the manifest fix because the file names are not public API (the exports map exposes only . and package.json), and it matches the layout every affected release has shipped. One trade-off: TypeScript 4.5 and 4.6 with moduleResolution: "node" cannot resolve the top-level types entry when it ends in .d.cts. TypeScript 4.7 and later resolve it under every resolution mode. The README's warning that the package is ESM-only and needs NODE_OPTIONS=--experimental-require-module in CommonJS projects is also removed, since the package ships a CommonJS build.

The new packages/nestjs/src/cjs.test.ts checks that every path declared in package.json exists in the build. It also checks that require.resolve("@fedify/nestjs") resolves through the require condition to the declared target before loading it, since Node.js and Bun can also require() ESM. Both tests fail on the old manifest and pass with the fix under Node.js 22 and Bun 1.2.22, and pnpm --filter @fedify/nestjs test and test:bun pass (13 tests each). I also installed the packed tarball into a scratch npm project with NestJS 11 and @fedify/fedify 2.0.35. require() loaded the package on Node.js and Bun, import loaded it on Node.js, and tsc --noEmit passed for .cts, .mts, and .ts consumers under node16, nodenext, node10, and bundler. mise run check passes. mise run check-each nestjs already fails on 2.0-maintenance because packages/nestjs is not a member of the root Deno workspace, so I ran deno check, deno lint, and deno fmt --check on the new test file directly instead.

When this is merged forward to main, the nestjs entry in KNOWN_DECLARATION_PROBLEMS in scripts/check_types.ts and the nestjs exemption in scripts/package_exports.mjs need to go, since a stale KNOWN_DECLARATION_PROBLEMS entry fails the check. 2.4-maintenance has neither.

Fixes #1424.

require("@fedify/nestjs") failed with MODULE_NOT_FOUND because the
package manifest pointed its CommonJS entry point and declarations at
dist/index.js and dist/index.d.ts, which the build no longer emits.
Since the tsdown 0.21 upgrade in a05a6b9, tsdown defaults to fixed
extensions for platform "node" and emits dist/index.cjs and
dist/index.d.cts instead.  That upgrade adjusted the other packages'
configs with outExtensions but missed this one, so every release since
2.0.9 shipped a manifest that does not match its files.  NestJS projects
compile to CommonJS by default, so this is the usual way to load the
integration.

The manifest's main, types, and exports["."].require entries now point
to the files that are actually built.  New regression tests check that
every path declared in package.json exists in the build, and that
require() resolves through the "require" condition and loads the
CommonJS build.  Both fail on the old manifest under Node.js and Bun.
The README no longer describes the package as ESM-only, requiring
--experimental-require-module in CommonJS projects.

Fixes fedify-dev#1424

Assisted-by: Claude Code:claude-opus-5-5
Assisted-by: Codex:gpt-6-astra
Assisted-by: OpenCode:kimi-k3.1-pro
Assisted-by: Claude Code:claude-fable-5-2
@dahlia dahlia self-assigned this Nov 12, 2026
@dahlia dahlia added runtime/node Node.js runtime related component/build Build system and packaging integration/nestjs NestJS integration (@fedify/nestjs) labels Nov 12, 2026
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The NestJS package manifest now points CommonJS loading and declaration resolution to .cjs and .d.cts files. Tests check that declared targets exist and that require("@fedify/nestjs") exposes the expected functions. The changelog and README were updated; ESM targets remain unchanged.

Changes: NestJS CommonJS loading

Layer / File(s) Summary
CommonJS targets and validation
packages/nestjs/package.json, packages/nestjs/src/cjs.test.ts, packages/nestjs/README.md, changes.d/nestjs/commonjs-entry-point.md, CHANGES.md
The manifest points CommonJS entry and declaration fields to .cjs and .d.cts files. Tests check that manifest targets exist and that require() resolves to the declared entry and exposes integrateFederation and FedifyModule. The README removes the runtime note about NODE_OPTIONS=--experimental-require-module; the changelog records the change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • fedify-dev/fedify#1357: Adds type declaration checks and package-export validation that use the NestJS package manifest fields changed here.

Suggested reviewers: sij411, 2chanhaeng

Merge Risk: Minimal · up to 188f8

This change fixes CommonJS loading of @fedify/nestjs by pointing the package manifest at the files that are actually emitted. ESM consumers are unaffected, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Fix the CommonJS entry point of @fedify/nestjs" names the main change. The PR repoints the package manifest's CommonJS entry and declaration targets from dist/index.js and dist/index.d.ts t…
Description check Passed The description is closely related to the changeset. It explains the MODULE_NOT_FOUND failure, the tsdown 0.21 output-extension cause, the manifest changes to main, types, and exports["."].require, th…
Linked Issues check Passed Issue #1424 asks that main and require.default point to dist/index.cjs, and that types and require.types point to dist/index.d.cts. The diff of packages/nestjs/package.json (merge base t…
Out of Scope Changes check Passed All changed files relate to the CommonJS loading fix in #1424. The package.json diff changes only the CommonJS main, types, and require targets. cjs.test.ts verifies that fix. The README cha…
Full details: Title check

Explanation

The title "Fix the CommonJS entry point of @fedify/nestjs" names the main change. The PR repoints the package manifest's CommonJS entry and declaration targets from dist/index.js and dist/index.d.ts to dist/index.cjs and dist/index.d.cts, which fixes require() loading. The title is specific and matches the changeset and linked issue #1424.

Full details: Description check

Explanation

The description is closely related to the changeset. It explains the MODULE_NOT_FOUND failure, the tsdown 0.21 output-extension cause, the manifest changes to main, types, and exports["."].require, the new cjs.test.ts tests, the README warning removal, and the follow-up checker-exemption removals when forwarding to main. It fully describes the changes.

Full details: Linked Issues check

Explanation

Issue #1424 asks that main and require.default point to dist/index.cjs, and that types and require.types point to dist/index.d.cts. The diff of packages/nestjs/package.json (merge base to head) sets main to ./dist/index.cjs, types to ./dist/index.d.cts, exports["."].require.types to ./dist/index.d.cts, and exports["."].require.default to ./dist/index.cjs. The import entries are unchanged. The PR adds packages/nestjs/src/cjs.test.ts, which checks that declared manifest targets exist and that require.resolve("@fedify/nestjs") resolves to the declared CommonJS target. The changelog entry requested by #1424 is present in changes.d/nestjs/commonjs-entry-point.md. The #1424 request to remove the KNOWN_DECLARATION_PROBLEMS and package-exports exceptions is deferred to main in the PR description. Repository read of scripts/check_types.ts at head failed because the path does not exist on this branch, so no exception removal can be assessed here. The core manifest and test requirements are met.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the CommonJS loading fix in #1424. The package.json diff changes only the CommonJS main, types, and require targets. cjs.test.ts verifies that fix. The README change removes the CommonJS NODE_OPTIONS=--experimental-require-module warning, which describes the old CommonJS-loading limitation that this fix resolves. The changelog entry documents the user-visible CommonJS change that #1424 requires. No unrelated change was found in the reviewed files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: cd325f2d-b36d-43f2-8685-0ff8f2b656b6
Commits

Reviewing files that changed from the base of the PR and between 4342c98 and 188f8ec.

Files selected for processing: 5

  • CHANGES.md
  • changes.d/nestjs/commonjs-entry-point.md
  • packages/nestjs/README.md
  • packages/nestjs/package.json
  • packages/nestjs/src/cjs.test.ts
Files with no reviewable changes: 1

  • packages/nestjs/README.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@dahlia dahlia linked an issue Nov 12, 2026 that may be closed by this pull request
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T12:51:20.714860Z 188f8ec PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dahlia
dahlia merged commit 4d2d041 into fedify-dev:2.0-maintenance Nov 14, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/build Build system and packaging integration/nestjs NestJS integration (@fedify/nestjs) runtime/node Node.js runtime related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@fedify/nestjs cannot be loaded with require()

1 participant