Skip to content

fix: show require() error on unsupported directory import - #6354

Merged
mark-wiemer merged 1 commit into
mochajs:mainfrom
mostafaNazari702:dir-import
Sep 19, 2026
Merged

mark-wiemer merged 1 commit into
mochajs:mainfrom
mostafaNazari702:dir-import

Conversation

@mostafaNazari702

Copy link
Copy Markdown
Contributor

PR Checklist

Overview

When loading a test file fails both ways mocha now shows the require() error if import() only failed with ERR_UNSUPPORTED_DIR_IMPORT. That error just means import() hit a folder path require() handles fine so you would see "Directory import is not supported" instead of the missing module or compile error you were actually after.

As i did mention in the backing issue this doesn't reproduce on main right now because #5498 only landed on Mocha v11.x so the || from #5408 is still here and a .ts file on its own picks the require() error by luck. Put the && back and the bug returns which is why i made this its own check instead of folding it into that condition.

and i left the forward port alone since it needs the ".....with a loader" test sorted out too and didnt touch the "show both errors" work in #5235.

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.44%. Comparing base (d59467a) to head (30456be).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6354      +/-   ##
==========================================
+ Coverage   63.38%   63.44%   +0.05%     
==========================================
  Files          64       64              
  Lines        4971     4973       +2     
  Branches     1102     1127      +25     
==========================================
+ Hits         3151     3155       +4     
+ Misses       1820     1818       -2     

☔ View full report in Codecov by Harness.
📢 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.

@mark-wiemer mark-wiemer changed the title fix: keep require() error on insupported directory import fix: keep require() error on unsupported directory import Sep 19, 2026
@mark-wiemer mark-wiemer changed the title fix: keep require() error on unsupported directory import fix: show require() error on unsupported directory import Sep 19, 2026
@mark-wiemer
mark-wiemer merged commit a68344f into mochajs:main Sep 19, 2026
190 of 192 checks passed
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: esm-utils.js#requireModule() masks more helpful requireErr in some cases

2 participants