type-comparator icon indicating copy to clipboard operation
type-comparator copied to clipboard

Angular warns on CommonJS or AMD dependencies

Open AlexElin opened this issue 2 years ago • 5 comments

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

AlexElin avatar Feb 23 '23 11:02 AlexElin

Let me dive into the problem. :)

lightness avatar Feb 23 '23 11:02 lightness

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

tsconfig.json

AlexElin avatar Feb 23 '23 16:02 AlexElin

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 😄

lightness avatar Feb 23 '23 18:02 lightness

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

for me it works

image

vasaeps3 avatar Feb 24 '23 23:02 vasaeps3

@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.

AlexElin avatar Mar 01 '23 18:03 AlexElin