".mts" and ".cts" default format
See original GitHub issueShouldn’t the config have these defaults to follow the TypeScript logic?
{
".mts": {
"format": "esm"
},
".cts": {
"format": "cjs"
}
}
One could also argue that these extensions format shouldn’t even be configurable and force these formats, just as .cjs forces commonjs and .mjs forces ecmascript modules
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
`.mts` is a cool file extension (TypeScript ES modules)
.mts is a cool file extension (TypeScript ES modules) ... that "Prettier will now format files with .mts and .cts extensions as TypeScript....
Read more >What're the use cases for the mts and cts file extensions?
You use commonJS as the default for .js files, and selectively apply .mjs as needed. You set "type: "module" and use ESM ...
Read more >CTSProfile register does not support source format: pdf and ...
default coding does not allow 2 renditions of the same format attached to a document. Suggest create a new format based on pdf,...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
When TypeScript generates declaration files for .mts and .cts , their ... to import CommonJS modules as if they were ES modules with...
Read more >Luke Edwards on Twitter: "Introducing `tsm` – TypeScript ...
Here's an example `tsm.js` config file. It's *completely* optional – tsm includes the defaults you're likely to want/need, but you can ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I understand you, but I don’t think you’re understanding me.
Forcing a format would break this example. That’s because when the
src/math.mjs
– orsrc/math.mts
for that matter – is loaded, your suggestion would always make it result in ESM syntax (because, natively, it should/is). However, if that were to happen, then thenode -r tsm test/math.ts
case would have code that looks like this:Instead, for tsm transpilation, we need to ignore the file’s required format and transform it to the usage’s desired format. This can only work if the converter itself produces semantically correct format conversion … and esbuild does.
So instead, when you run
node -r tsm test/math.ts
on the above example, you should get this:The semantics are preserved. And the same guarantee happens when you run
tsm
directly or use--loader tsm
except everything is coerced into ESM syntax instead.your example doesn’t have anything to do with what I mentioned, what I am suggesting is following the Typescript 4.5 new convention of
.mts
is always ESM and.cts
is always CJS, that’s it, following this convention allows you to specify what is the expected format of the transpilation, since I will know that a typescript file with .cts will have “require” available, while “.mts” will always be esm, that’s it