Skip to content

fix: serialize ESM loader TypeScript errors#2172

Open
puneetdixit200 wants to merge 1 commit into
TypeStrong:mainfrom
puneetdixit200:fix/2111-esm-tsconfig-diagnostics
Open

fix: serialize ESM loader TypeScript errors#2172
puneetdixit200 wants to merge 1 commit into
TypeStrong:mainfrom
puneetdixit200:fix/2111-esm-tsconfig-diagnostics

Conversation

@puneetdixit200
Copy link
Copy Markdown

Fixes #2111.

What changed

  • Convert TSError instances crossing the ESM loader worker boundary into a serializable Error copy.
  • Apply that conversion during loader registration and from the ESM loader hooks, so config and compile diagnostics survive Node's loader-worker serialization.
  • Add a regression fixture with an intentionally invalid tsconfig.json and assert the ESM loader prints the real TypeScript diagnostic instead of [Object: null prototype].

Verification

  • Red test before the fix: YARN_ENABLE_GLOBAL_CACHE=false YARN_CACHE_FOLDER=/tmp/ts-node-2111-yarn-cache YARN_NM_MODE=classic yarn test-spec ./dist/test/esm-loader.spec.js --match '*reports invalid tsconfig diagnostics from the ESM loader*'
  • YARN_ENABLE_GLOBAL_CACHE=false YARN_CACHE_FOLDER=/tmp/ts-node-2111-yarn-cache YARN_NM_MODE=classic yarn build-tsc
  • YARN_ENABLE_GLOBAL_CACHE=false YARN_CACHE_FOLDER=/tmp/ts-node-2111-yarn-cache YARN_NM_MODE=classic yarn lint
  • YARN_ENABLE_GLOBAL_CACHE=false YARN_CACHE_FOLDER=/tmp/ts-node-2111-yarn-cache YARN_NM_MODE=classic yarn test-spec ./dist/test/esm-loader.spec.js --match '*reports invalid tsconfig diagnostics from the ESM loader*'
  • YARN_ENABLE_GLOBAL_CACHE=false YARN_CACHE_FOLDER=/tmp/ts-node-2111-yarn-cache YARN_NM_MODE=classic yarn test-spec ./dist/test/esm-loader.spec.js --match '*should throw type errors without transpile-only enabled*'
  • YARN_ENABLE_GLOBAL_CACHE=false YARN_CACHE_FOLDER=/tmp/ts-node-2111-yarn-cache YARN_NM_MODE=classic yarn test-spec ./dist/test/diagnostics.spec.js
  • git diff --check

I also tried the full esm-loader.spec.js file locally, but the Node 24.15.0 runtime trips several existing expectations unrelated to this change, including source-map line expectations, import-assertion syntax, and deprecation-warning stderr assertions.

@puneetdixit200 puneetdixit200 force-pushed the fix/2111-esm-tsconfig-diagnostics branch from a2aa830 to 49ea0c5 Compare May 23, 2026 17: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.

Cryptic error on invalid tsconfig.json, e.g. if attempting to extend nonexistent tsconfig file

1 participant