From 1dbb156695070e54ca46e6a5eeb8a49af8fe2208 Mon Sep 17 00:00:00 2001 From: caelum0x Date: Wed, 28 Oct 2026 00:58:02 +0300 Subject: [PATCH] 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 --- gitgram/backend/tsconfig.json | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gitgram/backend/tsconfig.json b/gitgram/backend/tsconfig.json index b4640192..649e67a7 100644 --- a/gitgram/backend/tsconfig.json +++ b/gitgram/backend/tsconfig.json @@ -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 + } }