polkadot-js / common

Utilities and base libraries for use across polkadot-js for Polkadot and Substrate. Includes base libraries, crypto helpers and cross-environment helpers.
Apache License 2.0
252 stars 142 forks source link

Angular suggests not to use CommonJS modules #1003

Closed franklloydteh closed 3 years ago

franklloydteh commented 3 years ago

I get the following errors when adding "@polkadot/ui-keyring": "0.78.1" to the package.json of an Angular project and doing an ng build. This results in a larger build file. Would it be possible to replace dependencies on CommonJS Modules?

Warning:  @polkadot\keyring\node_modules\@polkadot\util-crypto\sha512\asU8a.js depends on 'tweetnacl'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning:  @polkadot\keyring\node_modules\@polkadot\util-crypto\scrypt\encode.js depends on 'scryptsy'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning:  @polkadot\keyring\node_modules\@polkadot\util-crypto\blake2\asU8a.js depends on 'blakejs'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning:  @polkadot\keyring\node_modules\@polkadot\util-crypto\mnemonic\bip39.js depends on 'hash.js'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning:  @polkadot\keyring\node_modules\@polkadot\util-crypto\secp256k1\secp256k1.js depends on 'elliptic'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning:  @polkadot\keyring\node_modules\@polkadot\util-crypto\keccak\asU8a.js depends on 'js-sha3'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning:  @polkadot\keyring\node_modules\@polkadot\util-crypto\base58\bs58.js depends on 'base-x'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning:  @polkadot\keyring\node_modules\@polkadot\util-crypto\xxhash\xxhash64\asValue.js depends on 'xxhashjs'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

According to Angular Documentation

It is recommended that you avoid depending on CommonJS modules in your Angular applications. Depending on CommonJS modules can prevent bundlers and minifiers from optimizing your application, which results in larger bundle sizes. Instead, it is recommended that you use ECMAScript modules in your entire application. For more information, see How CommonJS is making your bundles larger.

jacogr commented 3 years ago

No. All the ones you have listed only have commonJS packages, e.g. .tweetnacl, scryptsy, blakejs... The polkadot-js libraries itself is ESM (default) & CJS via export maps.

For those packages listed, I would suggest logging an issue in their specific repos to publish to ESM and CJS. (This is unlikely to be actioned by the authors since it has no pre-compilation step, they are stable and they are written in native CJS. Additionally, since most of them are crypto-related, any changes to those packages don't get taken lightly)

polkadot-js-bot commented 3 years ago

This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.

polkadot-js-bot commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.