fix(backend): make npm run dev actually boot (ts-node/express-rate-limit type collision)

`npm run dev` (nodemon --exec ts-node) crashed on startup with 8 TS2769
errors ("RateLimitRequestHandler not assignable to Application") every
time -- the documented quick-start path in README.md never actually
worked.

Root cause: this is an npm workspaces monorepo. express-rate-limit is
only hoisted to the monorepo root node_modules, not nested under
gitgram/backend/node_modules. Its own .d.ts resolves `express` by
walking up node_modules from wherever the package physically lives, so
it lands on the root's hoisted express@4 (and @types/express-serve-
static-core@4.19.8) instead of this package's own pinned express@5.1.0
/ @types/express@5.0.5 -- producing a real-looking but spurious cross-
package type mismatch on every `app.use(limiter)` call.

`npx tsc` / `tsc --noEmit` (the actual build and CI gate) do not hit
this at all and stay green -- confirmed before and after this change.
Set `transpileOnly: true` for the dev-loop ts-node process (the
standard fix for this exact class of ts-node + monorepo hoisting
false positive), so `npm run dev` boots instead of crashing on typings
that aren't a real bug in this project's own code.

Verified for real, not just via tsc:
- Spun up throwaway local postgres+redis containers, ran
  `prisma migrate deploy` (4/4 migrations clean), booted the backend
  with `npm run dev`'s actual command -- it now boots and serves
  /health with a live DB connection; it previously hard-crashed before
  a single request.
- Re-ran the full messaging + cross-tenant IDOR flow live end-to-end:
  registered 3 real users, created a real group chat (A+B), both
  members send/read successfully (201/200), and a non-member (C)
  gets a real 403 on both GET /messages/chats/:chatId and
  POST /messages with that chatId -- the IDOR fix from 487e4312 still
  holds.
- Re-ran tests/messages.test.ts with and without this change (via git
  stash): identical 17 failed / 15 passed both times, proving this is
  the same pre-existing mocked-Prisma flakiness already documented in
  plans/back-catalog.md, not a regression from this fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
caelum0x 2026-10-28 00:58:02 +03:00
parent 0fc4f141c9
commit 1dbb156695

View File

@ -26,6 +26,24 @@
"sourceMap": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "tests"]
"exclude": ["node_modules", "dist", "tests"],
// `npm run dev` (nodemon --exec ts-node) refused to boot at all: this is an
// npm workspaces monorepo, and express-rate-limit is only hoisted to the
// *root* node_modules, not nested under backend/node_modules. Its own type
// declarations resolve `express` by walking up from where the package
// actually lives, so they land on the root's hoisted express@4 (and its
// @types/express-serve-static-core@4.19.8) instead of this package's own
// pinned express@5.1.0 / @types/express@5.0.5 -- producing a real-looking
// but spurious "RateLimitRequestHandler not assignable to Application"
// type error on every `app.use(limiter)` call. `npx tsc`/`tsc --noEmit`
// (the actual build + CI gate) do NOT hit this: they resolve cleanly and
// stay the source of truth for real type errors. `transpileOnly` makes the
// dev-loop ts-node process behave the same way most Node teams run
// ts-node in watch mode -- strip types fast, don't re-typecheck on every
// save -- so `npm run dev` boots instead of crashing on a cross-package
// typings collision that isn't a real bug in this project's own code.
"ts-node": {
"transpileOnly": true
}
}