lightness / type-comparator

Useful comparator functions written on Typescript
MIT License
53 stars 1 forks source link

Angular warns on CommonJS or AMD dependencies #9

Open AlexElin opened 1 year ago

AlexElin commented 1 year ago

When a class in Angular app uses types from the library, Angular prints the following warning while executing ng build. image

Versions Angular: v14+ (I've not checked on earlier ones). type-comparator: 0.2.9

lightness commented 1 year ago

Let me dive into the problem. :)

AlexElin commented 1 year ago

I suppose the module property in tsconfig.json should be changed from commonjs to at least ES2015.

tsconfig.json

lightness commented 1 year ago

That's true. But then other consumers cannot do require('type-comparator'). Just tested.... Even node-fetch made a major release to support ESM...

Not sure it's right direction... But may be someone help me to find a way to support both CJS and ESM 😄

vasaeps3 commented 1 year ago

@AlexElin I hope this link will help you https://angular.io/guide/build#configuring-commonjs-dependencies

for me it works

image
AlexElin commented 1 year ago

@vasaeps3 In effect it's just ignoring the warning (suppressing it). In my opinion a correct solution would be providing ESM modules.

There're a several ways to do this:

  1. Switch to ESM from CJS. It's a breaking change. However, the version of this library starts with 0. According to the semver docs, it's ok to change public API in this case.
  2. Provide both ESM and CJS.