microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.29k stars 12.39k forks source link

Design Meeting Notes, 6/4/2021 #44442

Closed DanielRosenwasser closed 2 years ago

DanielRosenwasser commented 3 years ago

ES Modules in Node

https://gist.github.com/weswigham/22a064ffa961d5921077132ae2f8da78

Airkro commented 3 years ago

So, I think there is no need to support JSX in mjs/cjs


I'm not a team member, I guess this issue is comment allowed, let me know if it's not, I'll delete this.

fatcerberus commented 3 years ago

mjs in node.js have some behavior not support in browsers, it's not pure ECMAScript

Can you clarify on this point? Browsers don't care about file extensions (only mimetypes), and IIRC module specifier resolution is implementation-defined per ECMAScript. I don't think there's anything non-standard there?

Airkro commented 3 years ago

@fatcerberus

Try to say it clear, I mean the code might be an ECMAScript-module, but it doesn't mean they have the same implementation:

// this line won't work in the browser
import fs from 'node:fs/promises';

// this line won't work in node.js
import func from 'http://example.org/test.js';

For a long time, we don't know *.js is ready for who, browser or node.js But now we know *.mjs/*.cjs is for node.js only.

Airkro commented 3 years ago

I thought JSX is a sugar designed to make HTML binding easier, it's for browser only.

But now I realize JSX is used in many SSR projects. run them in node.js is possible, I should change my mind.

BenBeattieHood commented 1 year ago

Has there been any further decision on the adoption of an .mtsx extension?

GoToLoop commented 1 year ago

I'd love for TS to recognize both ".mtsx" & ".ctsx" file extensions! Possibly emit them as ".mjsx" & ".cjsx" respectively.

yinzara commented 1 year ago

There is still no way now more than 2 years after this discussion to indicate in a CommonJS React project that a specific file is a TypeScript MJS module making it impossible in a TypeScript CJS application to use any ESM only dependency which now means react-dnd (the primary drag and drop utility) is no longer accessible to the majority of ReactJS apps as it has gone ESM only (ARGGGGGGGGG WHY!!!!!).

I am forced to use a .mjs file and completely remove all typing from my file and then use a combination of Suspense and Lazy to load it as a component in a CJS file.

EvanLovely commented 1 week ago

There is still no way now more than 2 years after this discussion to indicate in a CommonJS React project that a specific file is a TypeScript MJS module

Wish there was a solution here; anybody have one?