question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve experience for .cts/.cjs files in inferred projects

See original GitHub issue

In https://github.com/microsoft/TypeScript/issues/46698, we updated VS Code’s default module setting for inferred projects to be esnext. Now that we have .cts and .cjs files floating around, we ideally ought to allow the former to use import/export assignment syntax, and forbid both from using import.meta. Now that --module nodenext is out, that may be a better default that gets us most or all of the way there.

(Note that I’m not suggesting a change to the default --moduleResolution for inferred projects which is still node. IIRC, we may need changes to set the impliedNodeFormat of .cts/.cjs files even when moduleResolution is not one of the new modes, or we may need some other strategy to just silence some of these errors in .cts files under --module esnext.)

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewbranchcommented, May 26, 2022

@weswigham do you have ideas on what a reasonable course of action would be? Of course, the combination of options we have now, and any that we might consider moving to, is a bizarre fiction.

I almost wonder if .cts/.mts/.cjs/.mjs files should go into a separate inferred project that does have --module nodenext --moduleResolution nodenext 😬.

0reactions
andrewbranchcommented, Jun 1, 2022

In the editor, tsconfig init, or implicitly?

Inferred projects (editor) only.

Maybe we could use the presence of these extensions (maybe less reliable since some projects were telling people to use mjs on web for years) or a package.json as an indicator to swap the implicit module setting in the editor?

Yeah, we could do that as a more conservative alternative to the above. But I don’t think we can use the presence of these extensions to switch the implicit module resolution setting, as I think that might be too dramatic of a change (one mjs or cjs file causes us to find "type": "module" in the package.json and suddenly complain about extensionless imports when in fact the user was targeting a bundler or something)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 4.7
Node.js supports two extensions to help with this: .mjs and .cjs . .mjs files are always ES modules, and .cjs files are always...
Read more >
How to make IntelliSense aware of exports in package.json?
So long as I define the project's modules correctly, so that the same algorithm is being used by typescript & node.js, everything works ......
Read more >
TIP 27: Comprehensive Case Management for Substance ...
Comprehensive Case Management for Substance. Abuse Treatment. Treatment Improvement. Protocol (TIP) Series, No. 27. HHS Publication. No. (SMA) 15-4215.
Read more >
What're the use cases for the mts and cts file extensions?
cjs right? The problem is, in a TS project you can't explicitly manipulate JS files, because those files are being generated by the...
Read more >
Repurposing Cyanine Photoinstability To Develop Near ...
The favorable properties of cyanines (e.g., near-infrared (NIR) absorbance and emission) have made this class of dyes popular for a wide ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found