fix: preserve TypeScript compilation errors instead of masking as MOD…
#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.
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.