ESM module load #442
Comments
@gengjiawen file extension and directory resolution are no longer supported in the esm loader. If you put the full filename it will work index.js import {a} from './a.js'
console.log(a) There are a number of reasons people on the Modules Team like this change including better performance and web compatibility. There is support for the former algorithm with a flag There is still some discussion being had about the final behavior we'll land on with this. |
I'm going to close this but please feel free to keep the conversation going. |
There is two downside in this Typescript supportts generate js code without the extension, so if I change ts output to Common FE writingAlso it's quite common to use without extension, like react or vue. I think this will bring much confusion. |
IMO, what we want to see in the future should take precedence over current practices. Less magic and less divergence from browsers are benefits of not doing this. |
Referencing proposal that doesn't involve "magic" or |
IIRC TS does work fine with the extension, it just doesn't add extensions not present in the source. The following should be accepted by // a.ts
import b from './b.js';
// b.ts
export default 42; TSC should be smart enough to figure out that you meant |
Right, if you use the extension in your typescript, typescript will generate code that has the extension. :) |
When using typescript, adding the extension only works if you're working with js files. You can't import from './a.ts' |
@jcjolley -- in your typescript source, when importing another typescript file, use the that is, when importing import * as b from "b.js" the import path reflects what ends up in the compiled output, not the path to the typescript source |
See microsoft/TypeScript#35589 (comment) and the comments preceding it. |
index.js
a.js
Using Node.js 13.2
node index.js
The text was updated successfully, but these errors were encountered: