Skip to content

Conversation

@hk2166
Copy link

@hk2166 hk2166 commented Dec 2, 2025

#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.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 2, 2025

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

  • ✅ login: hk2166 / name: Hemant (fcb0816)

Copy link
Member

@mark-wiemer mark-wiemer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off the bat, let's:

  • de-dupe this code
  • add unit tests
  • see if we can narrow the message.includes section as these are pretty vague. We should identify which types of errors are being thrown

All this said, I'm still reviewing the underlying bug. Thanks for opening this promptly though :)

@mark-wiemer mark-wiemer self-assigned this Dec 3, 2025
@mark-wiemer
Copy link
Member

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.

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.

2 participants