Skip to content

Detect .cts and .mts files in loader utils#7131

Open
htunnicliff wants to merge 2 commits intoyarnpkg:masterfrom
htunnicliff:htunnicliff/mts-cts
Open

Detect .cts and .mts files in loader utils#7131
htunnicliff wants to merge 2 commits intoyarnpkg:masterfrom
htunnicliff:htunnicliff/mts-cts

Conversation

@htunnicliff
Copy link
Copy Markdown

@htunnicliff htunnicliff commented May 7, 2026

What's the problem this PR addresses?

Fixes #6595.

This change lets Yarn's ESM loader correctly detect TypeScript files that use .mts or .cts extensions.

How did you fix it?

I updated getFileFormat() in loaderUtils.ts to treat .mts as having a "module" format and .cts as having a "commonjs" format.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

Copy link
Copy Markdown
Member

@clemyan clemyan left a comment

Choose a reason for hiding this comment

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

You need to run yarn update:pnp:hook to compile and use the hook.

This change enables loading .cts and .mts files, but disables type-stripping entirely for them. You need the commonjs-typescript and module-typescript formats for that.

Please note that not all Node versions we support has type-stripping (and the aforementioned formats), and I don't fully understand how those formats interact with the --experimental-type-stripping and --no-experimental-type-stripping flags across Node versions. You need to factor those into determining what format to use here to match Node's default behavior, and add tests to test for those behavior.

@@ -0,0 +1,2 @@
releases:
"@yarnpkg/pnp": minor
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.

plugin-pnp and cli also need releases

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?]: ERR_REQUIRE_ESM in Yarn PnP mode using Node.js 22 with *.mts file and --experimental-strip-types flag

2 participants