Skip to content

fix: load mjs files correctly#5429

Merged
mark-wiemer merged 11 commits into
mainfrom
fix-5425
Aug 30, 2025
Merged

fix: load mjs files correctly#5429
mark-wiemer merged 11 commits into
mainfrom
fix-5425

Conversation

@mark-wiemer
Copy link
Copy Markdown
Member

PR Checklist

Overview

mjs files were sometimes loaded like cjs files despite their extension. In some versions of Node (including Node 20.19.4) this causes breaking issues caught by our tests. A separate PR will bump Node versions in CI.

Copy link
Copy Markdown

@trentm trentm left a comment

Choose a reason for hiding this comment

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

FWIW, this LGTM. :)

Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

I would want to give the Node.js folks a chance to respond here just to be safe.

Comment thread lib/nodejs/esm-utils.js Outdated
@mark-wiemer
Copy link
Copy Markdown
Member Author

@JoshuaKGoldberg what would the Node folks respond with? The documentation is clear that files with mjs are sent to the ESM loader, so we should do the same.

@JoshuaKGoldberg
Copy link
Copy Markdown
Member

🤷 No specific requests, just that I know they were working on this with us recently. I would feel off making non-trivial logic changes without including them.

@trentm
Copy link
Copy Markdown

trentm commented Aug 19, 2025

the Node folks

By "the Node folks", do you mean for example @legendecas who was involved with the recent #5366 changes?

Copy link
Copy Markdown
Contributor

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Would you mind updating the test in https://github.com/mochajs/mocha/blob/main/test/integration/compiler-esm.spec.js as well?

I think the test might be ineffective to catch the case described in #5425.

@mark-wiemer
Copy link
Copy Markdown
Member Author

mark-wiemer commented Aug 23, 2025

+1 to test coverage, not sure how I missed that!

Edit: lolol I was the one that opened this PR, I thought someone else wrote this code. Expect an updated test soon :)

@mark-wiemer
Copy link
Copy Markdown
Member Author

@legendecas, thanks for calling out test coverage, I think the new tests are good but I'd appreciate your review. I refactored existing ones to use a helper function so that the new tests don't triply-duplicate code.

Copy link
Copy Markdown
Contributor

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Looks great to me! I like the test flow, it's very clear. ✨

Comment thread test/integration/compiler-esm-only-loader.spec.js Outdated
@JoshuaKGoldberg
Copy link
Copy Markdown
Member

By the way:

✅ All checks have passed

This is lovely to see in PRs again. 🥲

@mark-wiemer
Copy link
Copy Markdown
Member Author

Failures are just Coveralls, going to merge this one :) (we will be moving to Codecov, ref #5436 )

@mark-wiemer mark-wiemer merged commit a947b9b into main Aug 30, 2025
89 of 93 checks passed
@mark-wiemer mark-wiemer deleted the fix-5425 branch August 30, 2025 04:11
kmalakoff added a commit to kmalakoff/tsds-mocha that referenced this pull request Dec 4, 2025
kmalakoff added a commit to kmalakoff/tsds-mocha that referenced this pull request Dec 4, 2025
lennonnikolas pushed a commit to lennonnikolas/mocha that referenced this pull request Jan 24, 2026
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: .mjs test files can be loaded with require() which breaks custom module loaders

4 participants