#3

Fix broken CJS npm publish caused by stale committed tsconfig.tsbuildinfo

Openmohamedelraghywants to merge intofrom

Problem

packages/*/tsconfig.tsbuildinfo (TypeScript's incremental build cache) was committed to git for all four packages (core, nestjs, express, fastify), while dist/ itself is gitignored.

That combination broke tsc -b's incremental logic: on a fresh checkout, dist/ doesn't exist, but the stale committed buildinfo told TypeScript "these outputs are already up to date relative to the sources," so tsc -b silently skipped re-emitting some of them.

Concretely, reqlog-core's published tarball (verified for 0.1.0 and 0.2.0) was missing dist/index.js and other CJS files that its own package.json main/exports.require point to. Any CommonJS consumer (e.g. a NestJS app built with default nest build, which targets CommonJS) failed at runtime with Error: Cannot find module '.../reqlog-core/dist/index.js' / MODULE_NOT_FOUND — even though tsc reported 0 compile errors. It's a silent partial-emit bug, not a type error.

Fix

  • Untracked tsconfig.tsbuildinfo from git in all four packages and added *.tsbuildinfo to .gitignore.
  • Updated each package's clean script to also remove *.tsbuildinfo, not just dist/, so prepack always starts from a truly clean state before publish.
  • Found and fixed a related leak: tsc -p tsconfig.esm.json was emitting its buildinfo inside dist/ (dist/tsconfig.esm.tsbuildinfo). Since packages/core/package.json whitelists dist via files, that stray file was slipping into the published tarball regardless of .gitignore/.npmignore. Added an explicit tsBuildInfoFile to each tsconfig.esm.json so it's written outside dist/ instead.

Verification

  • Clean rebuild of reqlog-core emits the complete CJS set: dist/index.js, dist/index.d.ts, dist/ring-buffer.js, dist/sse-manager.js, dist/static-handler.js, dist/utils.js.
  • npm pack --dry-run in packages/core lists the full CJS + ESM set, with no .tsbuildinfo in the tarball.
  • reqlog-nestjs builds cleanly (previously failed with TS7016: Could not find a declaration file for module 'reqlog-core').
  • require() against the packed tarballs resolves ReqlogServer, RingBuffer, createInterceptor (core), and the express/fastify middleware, in all cases correctly loading reqlog-core as a real dependency.
  • Full monorepo bun run build and bun run test (35 tests) pass from a clean state.

Test plan

  • rm -rf packages/*/dist packages/*/tsconfig*.tsbuildinfo && bun run build succeeds
  • cd packages/core && npm pack --dry-run lists dist/index.js and no .tsbuildinfo
  • bun run test passes

Activity

2
mohamedelraghy3mo ago

Heads up for reviewers: examples/nestjs-example still fails today, even with this fix applied to the repo — it installs reqlog-core/reqlog-nestjs from the npm registry (not the local workspace), and the currently published 0.2.0 has the exact broken CJS build this PR fixes. It'll keep failing with MODULE_NOT_FOUND on reqlog-core/dist/index.js until a new version is published to npm. There's also a separate, unrelated issue where the example is missing the start:dev script that CONTRIBUTING.md tells contributors to run.

Filed both as #4 so they don't get lost — not blocking this PR, just flagging so the example gets re-verified after the next npm release.