mu-semtech / mu-javascript-template

Template for running javascript/express microservices
4 stars 17 forks source link

`type: "module"` support #63

Open Windvis opened 6 months ago

Windvis commented 6 months ago

Split off from #38 to have the discussion without specific implementation details.

The js template currently transpiles the code to CJS, so we can't easily import ESM modules (in a sync way) in our services. This can become an issue since there are npm packages out there that only publish ESM code now. Since we already write ESM-like code, (or TS) it might be worthwhile to change the setup to output ESM instead.

Some caveats mentioned in #38:

Windvis commented 6 months ago

Someone posted this in the Ember Discord: https://joyeecheung.github.io/blog/2024/03/18/require-esm-in-node-js/

So it seems that the main reason why we wanted this change (cjs can't sync import esm) will not be an issue anymore in the future. I do still think it's a better setup though, especially since we already write ESM-ish code anyways.

madnificent commented 6 months ago

How does the extension work with respect to transpiling coffeescript and typescript code? Does the extension "stick" to the original extension or does everything need a .js postfix?

Windvis commented 6 months ago

It needs to be .js in the transpiled file, yes. I'm not 100% sure what that means in practice for the template here.