So I m updating our app …
So I’m updating our app to Angular 10, and with that I’m using a dependency which is my own 3rd-party library (https://github.com/tanepiper/rxjs-primitives) and I’m now getting warnings about it not being a ECMAScript module but a CommonJS one - what’s the setting I need to change to publish the library to NPM correctly for tree shaking tanepiper/rxjs-primitives
Responses:
This is a new warning that angular 10 introduced. I am not familiar with the ins and outs unfortunately but I know it is specific to v10. Maybe start there and do some looking around? Maybe angular has some resources around publishing libraries now?
The library itself isn’t Angular, I actually use @nrwl/node for it to create a publishable package and inside it’s just TS functions with some dependency on RxJS. I’d assume it’s a TS setting or some change to the way I’m exporting?
Using tsconfig.json you can adapt the module type through the “module” compiler option. I suppose that’s where you need to look at
Yea I’ve tried that - it’s already esnext
but the contents of the dist
folder still has code compiled with require()
Mh I think that you can define the “module” option to ES201x, ES202x or ESNext and also look at the “target” option to define the language variant that you’re targeting
Check out this article: https://medium.com/@tommedema/typescript-confusion-tsconfig-json-module-moduleresolution-target-lib-explained-65db2c44b491
If you’re publishing packages that could have the potential of being used on the web, use the @nrwl/web:builder
It’ll set the proper fields in the package.json for use with esm, fesm, etc