Skip to content

refactor(esm): migrate package to ES modules - #3

Open
NedcloarBR wants to merge 1 commit into
masterfrom
refactor/esm-migration
Open

NedcloarBR wants to merge 1 commit into
masterfrom
refactor/esm-migration

Conversation

@NedcloarBR

Copy link
Copy Markdown
Member

The package already declared "type": "module" while tsconfig emitted CommonJS. The resulting .d.ts re-exported paths without extensions:

export * from "./entities";

nodenext consumers cannot resolve that, so every named export silently disappeared — the N-D-B project failed with 36 TS2305: Module "@ndb/database" has no exported member errors.

Changes

  • tsconfig: module/moduleResolution from CommonJS to nodenext
  • explicit .js / /index.js extensions on relative imports (68 across 21 files)
  • datasource.ts: __dirnameimport.meta.dirname for the migration and seed globs
  • scripts/help.js: requireimport ... with { type: "json" }
  • ts-nodetsx: the TypeORM cli-ts-node-esm.js wrapper relies on --loader ts-node/esm, deprecated on Node 22. Scripts now use --import tsx against typeorm/cli.js directly, dropping the wrapper subprocess.

Validation

  • yarn build clean; emitted .d.ts now carries extensions
  • consuming project type-checks at 0 errors against this build
  • migration:show reaches the database (fails only on connection refused, no local Postgres)

Migrations were not exercised against a live database — no Docker available in this environment.

Paired with the ESM migration in the N-D-B repository.

The package.json already declared "type": "module" while tsconfig emitted
CommonJS, so the published .d.ts re-exported paths without extensions
("./entities") that nodenext consumers could not resolve — every named
export silently disappeared.

- tsconfig: module/moduleResolution CommonJS -> nodenext
- add explicit .js and /index.js extensions to relative imports
- datasource: __dirname -> import.meta.dirname for migration/seed globs
- scripts/help.js: require -> import with { type: "json" }
- replace ts-node with tsx: the TypeORM cli-ts-node-esm.js wrapper relies on
  --loader ts-node/esm, deprecated on Node 22
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.

1 participant