Skip to content

fix(chat-service): remove dead runtime path-alias registration crashing prod boot - #201

Merged
ihabkhaled merged 1 commit into
mainfrom
worktree-fix-chat-service-esm-dirname
Sep 2, 2026
Merged

fix(chat-service): remove dead runtime path-alias registration crashing prod boot#201
ihabkhaled merged 1 commit into
mainfrom
worktree-fix-chat-service-esm-dirname

Conversation

@ihabkhaled

Copy link
Copy Markdown
Owner

Summary

  • dist/main.js crashed on every single boot with ReferenceError: __dirname is not defined in ES module scope — chat-service's package.json has "type": "module", and __dirname does not exist in ES modules.
  • Root cause: registerTsConfigPaths({ baseUrl: __dirname, ... }) in main.ts was added when this service briefly built with tsgo alone (commit 4e3ce3abc) and needed runtime path-alias resolution. Once tsc-alias was added back to chat-service's build script (matching every other service), it started rewriting @app/*/@common/*/etc. to real relative ./app/*.js imports at build time — making the runtime registration fully redundant. It was never removed, so it kept unconditionally referencing __dirname on every boot.
  • Fix: deleted the dead registerTsConfigPaths block and its tsconfig-paths import/dependency. No other service has this pattern (confirmed by repo-wide grep) and no other file in chat-service depends on it.

Release notes

chat-service is broken in production right now — every container crashes immediately on boot. This restores it to booting correctly.

Remaining work

None. This is a minimal, targeted fix — two files changed, nothing else touched.

Test plan

  • npx tsgo --noEmit — clean
  • npm run lint — 0 errors (71 pre-existing warnings, unrelated to this change)
  • npm run test — 1616/1616 tests passing (2 suites hit a pre-existing Windows/Jest path-resolution flake unrelated to this change — verified the flaky files pass 26/26 in isolation)
  • npm run build — confirmed dist/main.js contains zero __dirname references and zero bare @app//@common//@infrastructure//@modules/ specifiers (tsc-alias already resolves all of them to relative .js imports)
  • Booted dist/main.js directly: it now proceeds through NestJS module resolution and DI all the way to AppConfig.validate(), failing only on missing env vars in this isolated worktree (expected — no .env here). Previously it crashed before a single import even resolved.

…ng prod boot

dist/main.js crashed on every boot with "ReferenceError: __dirname is not
defined in ES module scope" — chat-service's package.json has
"type": "module", and __dirname does not exist in ES modules.

registerTsConfigPaths({ baseUrl: __dirname, ... }) was added when this
service briefly built with tsgo alone and needed runtime path-alias
resolution (chat-service commit 4e3ce3a). Once tsc-alias was added back
to chat-service's build script (matching every other service), it started
rewriting @app/* @common/* etc. to real relative ./app/*.js imports at
build time, making the runtime registration in main.ts fully redundant —
and it was never removed, so it kept running __dirname unconditionally on
every boot regardless of runtime module format.

Confirmed via a fresh build: dist/main.js contains zero @app/@common/
@infrastructure/@modules bare specifiers (tsc-alias already resolved them
all to relative paths) and zero __dirname references. Booted dist/main.js
directly: it now proceeds through NestJS module resolution and DI all the
way to AppConfig.validate(), failing only on missing env vars in this
isolated worktree (expected — no .env here), where it previously crashed
before a single import even resolved.

Also removes the now-unused tsconfig-paths runtime dependency.
@ihabkhaled
ihabkhaled merged commit ca12f3c into main Sep 2, 2026
17 checks passed
@ihabkhaled
ihabkhaled deleted the worktree-fix-chat-service-esm-dirname branch September 2, 2026 08:47
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