4 ms·
I understand the whole CommonJS Vs imports situation. I have been that vocal minority that keeps complaining about CommonJS support to library authors. But I h
by evnix 3y ago
I understand the whole CommonJS Vs imports situation.
I have been that vocal minority that keeps complaining about CommonJS support to library authors. But I have given it up for the greater good.
we have a standard now, CommonJS needs to go, why keep pushing non standard stuff in a 2023 article.
- deleted 3y ago[deleted]
- ushakov 3y agoThe problem is that you can import commonjs modules in ESM but not the other way around. For stepci (https://stepci.com https://stepci.com) we have chosen to not support ESM for this very reason. We want that the library “just works” for all our users
- edwinjm 3y agoIf you're using TypeScript, you have a build step anyway, so you can easily use ESM.
- ushakov 3y agoRemember we’re using Node. I don’t think TypeScript compiler supports importing ESM into CommonJS files. Basically we will have to move the library to ESM and then use a bundler like esbuild to compile it to CJS as well for compatibility. It’s a mess
- josteink 3y ago> It’s a mess I think everyone agrees about this. What people can’t agree about is how to fix it.
- vinnymac 3y agoI haven’t really struggled too much here. Maybe an aversion to bundlers exists, but I think tsup and vite are great and simple. We have turbopack on the horizon too. For small projects I don’t even need a configuration file for tsup to target both formats. For larger more complex projects vite configs tend to be under 50 LoC.
- herpdyderp 3y agoTry using the tsx package for running Node in situations like this. It magically “just works” https://www.npmjs.com/package/tsx https://www.npmjs.com/package/tsx
- spankalee 3y agoYou cannot import Common JS from standard JS modules in an environment that doesn't support Common JS, like... all browsers. Everything should be published as standard modules at this point.
- edwinjm 3y agoExactly.
- EMM_386 3y agoYes, when working with Angular, you'll see build warnings about CommonJS dependencies. > ▲ Module 'some-library' used by 'src/app/some.component.ts' is not ESM > CommonJS or AMD dependencies can cause optimization bailouts. > For more information see: https://angular.io/guide/build#configuring-commonjs-dependencies https://angular.io/guide/build#configuring-commonjs-dependen...