Skip to content

fix: none of the scripts ran; upgrade Nest 7 → 12 and TypeORM 0.2 → 0.3 - #1

Merged
ludejun merged 1 commit into
masterfrom
chore/maintenance-2026
Sep 23, 2026
Merged

ludejun merged 1 commit into
masterfrom
chore/maintenance-2026

Conversation

@ludejun

@ludejun ludejun commented Sep 23, 2026

Copy link
Copy Markdown
Owner

The headline

Nothing in this repo could be built, started or tested. Every npm script begins with cross-env, which was never in devDependencies:

$ pnpm build
sh: cross-env: command not found

Four dependencies used but never declared

cross-env, lodash (15 call sites), body-parser and jsonwebtoken. All four resolved through hoisting under npm/yarn and fail under pnpm's stricter layout.

  • lodash is now declared.
  • body-parser is replaced by Express's own json() / urlencoded() — built in since Express 4.16.
  • The jsonwebtoken import only supplied a type; it is gone.

Framework upgrades

Nest 7 → 12 HttpModule / HttpService moved from @nestjs/common to @nestjs/axios in Nest 8.
TypeORM 0.2 → 0.3 createConnection → DataSource, ConnectionOptions → DataSourceOptions, and findOne() now requires explicit where options.
@nestjs/cli pinned to 11 The 12 line pulls an ESM-only ora through @angular-devkit/schematics, which crashes on Node 22 with ERR_REQUIRE_CYCLE_MODULE.

Plus pg 8.23, helmet 4 → 8, express-rate-limit 5 → 8, class-validator 0.13 → 0.15, nodemailer 6 → 10, TypeScript 4.2 → 5.9.

Note

TypeORM 1.x is out and @nestjs/typeorm 12 accepts it, but 0.3 is what nearly all Nest documentation targets. Worth revisiting separately.

Bugs this surfaced

  • CatsService swallowed errors and returned them as data. Both methods ended in catch (err) { return err; }, so a failed query reached the client as a 200 with an Error object in the body instead of going through the error filter. Errors now propagate, with a regression test.
  • CatEntity was missing the columns the API accepts. The endpoint takes age and breed; the entity declared only id and name, so TypeORM silently dropped both on write.
  • The e2e spec used import * as request from 'supertest', which is not callable with esModuleInterop on.

Jest → Vitest

@nestjs/testing 12 is ESM-only, and Jest 30 cannot require() ESM before Node 24.9 — every suite failed to load. Vitest runs them through SWC, which implements emitDecoratorMetadata (esbuild does not), so Nest's DI resolves.

The two Cats specs were Nest CLI stubs that could not resolve their own dependencies — they had never run. Replaced with 9 tests mocking the repository via getRepositoryToken, covering both the service and the controller.

Also

  • ESLint 9 flat config with typescript-eslint, replacing ESLint 7. 0 errors.
  • Type-checking moved to its own tsconfig.typecheck.json: the CommonJS build's node resolution cannot read Vitest's type exports, so the two need different resolvers.
  • README split into Chinese README.md and English README_EN.md, both with badges and the full architecture notes. New CHANGELOG.md and bilingual CONTRIBUTING.md.
  • New ci.yml (lint, typecheck, test, build on Node 20 and 22) — unit tests only, since the e2e suite needs a live database.
  • Migrated to pnpm.

Verified

pnpm lint (0 errors), pnpm typecheck (0 errors), pnpm test (9 passing) and pnpm build all pass.

🤖 Generated with Claude Code

… 0.3

Every npm script starts with `cross-env`, which was never in devDependencies,
so nothing in this repo could be built, started or tested.

Four dependencies were used but never declared
- `cross-env` (all scripts), `lodash` (15 call sites), `body-parser` and
  `jsonwebtoken`. They resolved through hoisting under npm/yarn and fail under
  pnpm. lodash is now declared; body-parser is replaced by Express's own json()
  and urlencoded(); the jsonwebtoken import only supplied a type and is gone.

Framework upgrades
- Nest 7 -> 12. HttpModule / HttpService moved from @nestjs/common to
  @nestjs/axios in Nest 8.
- TypeORM 0.2 -> 0.3: createConnection -> DataSource, ConnectionOptions ->
  DataSourceOptions, and findOne() now needs explicit `where` options.
- @nestjs/cli is pinned to 11: the 12 line pulls an ESM-only `ora` through
  @angular-devkit/schematics, which crashes on Node 22 with
  ERR_REQUIRE_CYCLE_MODULE.
- pg, helmet 4 -> 8, express-rate-limit 5 -> 8, class-validator 0.13 -> 0.15,
  nodemailer 6 -> 10, TypeScript 4.2 -> 5.9.

Bugs this surfaced
- CatsService swallowed errors: both methods ended in
  `catch (err) { return err; }`, so a failed query reached the client as a 200
  with an Error object in the body.
- CatEntity declared only id and name, while the endpoint accepts age and
  breed — TypeORM silently dropped both on write.
- The e2e spec used `import * as request from 'supertest'`, not callable with
  esModuleInterop on.

Jest -> Vitest
- @nestjs/testing 12 is ESM-only and Jest 30 cannot require() ESM before Node
  24.9. Vitest runs the suite through SWC, which implements
  emitDecoratorMetadata (esbuild does not), so Nest's DI resolves.
- The two Cats specs were Nest CLI stubs that could not resolve their own
  dependencies. Replaced with 9 tests that mock the repository and cover both
  the service and the controller, including the error-propagation regression.

Also
- ESLint 9 flat config with typescript-eslint, replacing ESLint 7. 0 errors.
- README split into Chinese README.md and English README_EN.md, plus a
  CHANGELOG, a bilingual CONTRIBUTING and a CI workflow.
- Migrate to pnpm.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ludejun
ludejun merged commit e147465 into master Sep 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants