microsoft / TypeScript

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

Support ".mjs" input files #27957

Closed mjbvz closed 3 years ago

mjbvz commented 6 years ago

From @Sti2nd on October 7, 2018 16:17

import { timpaniSounds } from "./soundImport.mjs";

In the above example VS code will show all javascript files when writing "./", but not javascript module files. So I didn't see the above file in the list when trying to import it. Not sure if this is a bug or a feature request.

Copied from original issue: Microsoft/vscode#60103

weswigham commented 3 years ago

Fixed by the addition of module: node12 with #45884 (which includes support for .mjs and .mts files).

frank-dspeed commented 2 years ago

this future will only be in typescript 4.6 it got droped from the 4.5 time schedule https://github.com/microsoft/TypeScript/issues/46452#issuecomment-960454410

as Daniel (TypeScript Team Lead) pointed out

weswigham commented 2 years ago

(Technically support did ship in 4.5, it relies on the module: nodenext setting, it just issues an error saying it's experimental)

frank-dspeed commented 2 years ago

@weswigham does nodenext include everything that was included in node12 (package.json exports fild)?

weswigham commented 2 years ago

They're mostly the same (except for some export map edge cases and the implied target), and both modes are included.

knightedcodemonkey commented 1 year ago

Is this really fixed? It doesn't seem so, at least not in all use cases. Particularly, there is no way to support a mixture of .mts and .ts when using --module commonjs, all the emitted .mjs files will be broken and not consumable by either module system. It is impossible with tsc as far as I can tell, so I would not consider this fixed.

For the reason why, see my comment on #50985. This should be reopened.