Closed DanielRosenwasser closed 2 years ago
mjs/cjs
is for node.js
only, not for browsers or deno
commonjs
never be a part of ECMAScript
, not supported in browsersmjs
in node.js
have some behavior not support in browsers, it's not pure ECMAScript
JSX
is for html in browser
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.
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?
@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.
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.
Has there been any further decision on the adoption of an .mtsx
extension?
I'd love for TS to recognize both ".mtsx" & ".ctsx" file extensions! Possibly emit them as ".mjsx" & ".cjsx" respectively.
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.
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?
ES Modules in Node
https://gist.github.com/weswigham/22a064ffa961d5921077132ae2f8da78
.tsx
syntax and how it affected JS module support..cjs
and.mjs
need a corresponding input format for them..cts
and.mts
.jsx
->.tsx
.mjsx
->.mtsx
?.mts
..mjsx
a thing?.mjs
can contain JSX..js
files we always parse JSX anyway..cjs
and.mjs
allowJs
.js
files..cjsx
,.mjsx
..js
and.jsx
in today's implementation?.cts
and.mts
extensions.cjs
and.mjs
respectively..cjs
" and "emit as.mjs
" from.ts
input..ctsx
and.mtsx
?.cts
includes JSX,.mts
includes JSX.<Type>expression
)expression as Type
<T>(x: T) => x
)<T,>(x: T) => x
or<T extends unknown>(x: T) => x
>
in the arrow is not illegal..cjs
for React? It sounds like a Node-ism..cts
and.mts
without JSX support and add it later..ts
syntax conflicting with JSX syntax.let x = <Foo>yadda;
- have to disallow thislet f = <T>(x: T) => x;
- have to disallow this<T>3</T>
// @jsx: true
.tsx
->.mts
being weird...but works better for.ts
->.mts
..mts
and.cts
parsed as.ts
, additional grammar error to inform people of what you meant if you wrote specific constructs..cjs
,.mjs
.d.cts
,.d.mts
.d.mts
if you import with an.mjs
extension, right?.d.tson
?