First of all, I'm NOT talking about "allowedCommonJsDependencies"
. That's just a matter of suppressing warnings. What I want to do is author an npm package, to be used by Angular projects as well as non-Angular projects, so that there will be no warnings which have to be suppressed.
My package already contains ESM-style modules, as well as CommonJS (and even minified UMD). There are both ES6 (ES2015) and ES5 code versions available. Here's the start of my package.json:
{
"name": "@tubular/util",
"version": "3.3.0",
"description": "Miscellaneous utility functions",
"browser-es5": "dist/web5/index.js",
"browser-es6": "dist/web/index.js",
"main": "dist/es5/index.js",
"module": "dist/index.js",
"es2015": "dist/es6/index.js",
"esm2015": "dist/index.js",
"typings": "dist/index",
"sideEffects": false,
The code at dist/index.js
looks like this:
export * from './browser-graphics-util';
export * from './browser-util';
export * from './misc-util';
export * from './string-util';
...and all the code that is exported above is written in the ESM style, using import
, not require
.
So why is Angular complaining about the CommonJS code, instead of happily grabbing the ESM code and using that instead, without any need for warnings?
Full source code here: https://github.com/kshetline/tubular_util