Skip to content

fix: surface ts-node compile errors - #5572

Merged
mark-wiemer merged 5 commits into
mochajs:mainfrom
sam-super:ts-mod-not-found
Dec 31, 2025
Merged

mark-wiemer merged 5 commits into
mochajs:mainfrom
sam-super:ts-mod-not-found

Conversation

@sam-super

Copy link
Copy Markdown
Contributor

PR Checklist

Overview

Prevents "Cannot find module" when there are TS errors by prevent fallback to 'import()' when it errors.

The downside is this is tightly coupled to how ts-node throws errors when loading modules. However, this change seems unlikely to have any unexpected side-effects, so the risk is that it wont help if someone is using a different TS loader, but it's still a net gain for most.

Prevents "Cannot find module" when there are TS errors
@codecov

codecov Bot commented Dec 18, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.53%. Comparing base (9cc3ada) to head (6a64bdb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5572   +/-   ##
=======================================
  Coverage   93.52%   93.53%           
=======================================
  Files          57       57           
  Lines        4465     4467    +2     
  Branches      918      919    +1     
=======================================
+ Hits         4176     4178    +2     
  Misses        289      289           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with the strategy, but would really like a spot check from another maintainer to make sure there's no way we can get around it.

Just requesting changes on moving the debug() line.

Thanks!

Comment thread lib/nodejs/esm-utils.js Resolved
Comment thread lib/nodejs/esm-utils.js Resolved
Comment thread test/node-unit/esm-utils.spec.js Resolved
@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author waiting on response from OP or other posters - more information needed label Dec 18, 2025
sam-super and others added 3 commits December 19, 2025 07:53
…-mod-not-found

* 'ts-mod-not-found' of github.com:sam-super/mocha:
  feat: add mocha.mjs export (mochajs#5527)
  docs: bumped docs-next Astro to ^5.16.6 (mochajs#5574)
  build(dev-deps): upgrade `markdownlint-cli` to latest v0.46.0  (mochajs#5560)
@mark-wiemer mark-wiemer removed the status: waiting for author waiting on response from OP or other posters - more information needed label Dec 19, 2025
@mark-wiemer
mark-wiemer self-requested a review December 19, 2025 08:08

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks! 🙌

@JoshuaKGoldberg
JoshuaKGoldberg requested review from mark-wiemer and removed request for mark-wiemer December 24, 2025 17:54
@mark-wiemer

Copy link
Copy Markdown
Member

Test failure is known transient issue (#5361), merging. Thank you!

@mark-wiemer
mark-wiemer merged commit add4cf8 into mochajs:main Dec 31, 2025
79 of 80 checks passed
lennonnikolas pushed a commit to lennonnikolas/mocha that referenced this pull request Jan 24, 2026
* fix: surface ts-node compile errors

Prevents "Cannot find module" when there are TS errors

* fix: remove ts-node error condition check below debug logging
@SchroederSteffen

Copy link
Copy Markdown

Thanks for the fix. Could this be downported to v11?

@mark-wiemer

Copy link
Copy Markdown
Member

Created #6029 :)

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.

🐛 Bug: "Cannot find module" if module contains ts-node style 'TSError'

4 participants