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.

@trentm trentm left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FWIW, this LGTM. :)

@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 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

trentm commented Aug 19, 2025

Copy link
Copy Markdown

the Node folks

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

@legendecas legendecas left a comment

Copy link
Copy Markdown
Contributor

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

mark-wiemer commented Aug 23, 2025

Copy link
Copy Markdown
Member Author

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

@legendecas legendecas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

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

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
kmalakoff added a commit to kmalakoff/tsds-mocha that referenced this pull request Sep 1, 2026
kmalakoff added a commit to kmalakoff/tsds-mocha that referenced this pull request Sep 2, 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