mocha icon indicating copy to clipboard operation
mocha copied to clipboard

fix: preserve TypeScript compilation errors instead of masking as MOD…

Open hk2166 opened this issue 2 weeks ago • 2 comments

#5555 When ts-node or similar TypeScript compilers encounter a type error, the error was being caught and masked by fallback module loading logic, resulting in unhelpful "Cannot find module" messages instead of the actual TypeScript diagnostics.

This fix detects TypeScript compilation errors by checking for TS-specific patterns in error messages and throws them immediately without attempting fallback mechanisms, preserving the full diagnostic information for users.

Fixes issue where TypeScript errors in imported modules showed as "Cannot find module" rather than displaying the actual type error.

hk2166 avatar Dec 02 '25 04:12 hk2166

CLA Signed
The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: hk2166 / name: Hemant (fcb0816952c2aa7cb5cab1978ff7c5da62c68235)

RE "narrow the message.includes" section, we should be able to look at the error code instead. If the import error code is MODULE_NOT_FOUND and the require error is something more meaningful, we throw that instead. Ref https://github.com/mochajs/mocha/pull/5498/files#diff-30714d24f4a4acd4826e5f7e92f58922ed0ab41b1f0062ae2a46df6c5c899eb4 which also looks at the error code.

mark-wiemer avatar Dec 03 '25 05:12 mark-wiemer