Repository navigation
Fix the CommonJS entry point of @fedify/nestjs - #1428
Conversation
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
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
require("@fedify/nestjs")fails withMODULE_NOT_FOUNDbecause 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 enablesfixedExtensionby default and emits dist/index.cjs and dist/index.d.cts for the CommonJS build. That commit addedoutExtensionshooks 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'smain,module,types, andexportstargets against the files on disk; only these four nestjs entries were missing.This updates
main,types, andexports["."].requireto point to the files the build produces, as #1424 proposes. I considered restoring the old .js/.d.ts names withoutExtensionsinstead. I kept the manifest fix because the file names are not public API (theexportsmap exposes only.and package.json), and it matches the layout every affected release has shipped. One trade-off: TypeScript 4.5 and 4.6 withmoduleResolution: "node"cannot resolve the top-leveltypesentry 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 needsNODE_OPTIONS=--experimental-require-modulein 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 therequirecondition to the declared target before loading it, since Node.js and Bun can alsorequire()ESM. Both tests fail on the old manifest and pass with the fix under Node.js 22 and Bun 1.2.22, andpnpm --filter @fedify/nestjs testandtest:bunpass (13 tests each). I also installed the packed tarball into a scratch npm project with NestJS 11 and@fedify/fedify2.0.35.require()loaded the package on Node.js and Bun,importloaded it on Node.js, andtsc --noEmitpassed for .cts, .mts, and .ts consumers undernode16,nodenext,node10, andbundler.mise run checkpasses.mise run check-each nestjsalready fails on 2.0-maintenance because packages/nestjs is not a member of the root Deno workspace, so I randeno check,deno lint, anddeno fmt --checkon the new test file directly instead.When this is merged forward to main, the
nestjsentry inKNOWN_DECLARATION_PROBLEMSin scripts/check_types.ts and thenestjsexemption in scripts/package_exports.mjs need to go, since a staleKNOWN_DECLARATION_PROBLEMSentry fails the check. 2.4-maintenance has neither.Fixes #1424.