lichess-org / chessground

Mobile/Web chess UI for lichess.org
https://lichess.org
GNU General Public License v3.0
1.02k stars 262 forks source link

Fix invalid es module output, fixes #213 #215

Closed ruhibloodworth closed 2 years ago

ruhibloodworth commented 2 years ago

Adds .js extensions to all imports Imports in es modules are supposed to include the file extension the typescript team provides no way to automatically add extension in the emmited code and recommends using the .js extension in the src.

niklasf commented 2 years ago

Thanks for looking into this. It doesn't look right or at least very strange to me. How/where did you find this solution?

ruhibloodworth commented 2 years ago

I also thought it was weird. The typescript handbook shows the strange import syntax and there is a typescript bug report discussing the issue.

benediktwerner commented 2 years ago

I've had a similar issue before when writing a node application and being forced to output es modules because a dependency required it and I also ended up with this solution. Node and browsers require the extension when loading es modules and even though it's weird to use .js in TypeScript modules, it appears this is the solution that the TypeScript team endorses because they are committed to not rewriting any JS code including the imports when the target level is the same as the input i.e. when the input and output are both es modules and it's effectively just stripping types.

Though this shouldn't really be necessary when using a bundler. It seems that new versions of webpack enforce this for some reason but you can still just turn it off by setting resolve.fullySpecified to false in the webpack config.

niklasf commented 2 years ago

Alright, so looks like this will be indeed the future.