Moralis npm package installation does not work 100%

Hi, I have installed moralis to my angular project (npm i moralis) and imported moralis into the component just like it is done in the demo app " https://github.com/MoralisWeb3/demo-apps/tree/main/moralis-angular-app ". the demo app compile with a warning and still run:

“Warning: C:\Development\demo-apps-main\moralis-angular-app\src\app\app.component.ts depends on ‘moralis’. CommonJS or AMD dependencies can cause optimization bailouts.”

In my angular app I get multiple build errors of dependencies that could not be found, but it is in the node_modules folder.

below is the list of errors and warnings I get in my project:

  1. WARNING in ./node_modules/crypto-js/core.js
    Module not found: Error: Can’t resolve ‘crypto’ in ‘C:\Development\moralis-test\node_modules\crypto-js’

  2. WARNING in C:\Development\moralis-test\src\app\app.component.ts depends on ‘moralis’. CommonJS or AMD dependencies can cause optimization bailouts.

  3. WARNING in C:\Development\moralis-test\[email protected]\signing-key\lib.esm\elliptic.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

  4. ERROR in ./node_modules/eth-lib/lib/bytes.js
    Module not found: Error: Can’t resolve ‘crypto’ in ‘C:\Development\moralis-test\node_modules\eth-lib\lib’

  5. ERROR in ./node_modules/web3-eth-accounts/lib/index.js
    Module not found: Error: Can’t resolve ‘crypto’ in ‘C:\Development\moralis-test\node_modules\web3-eth-accounts\lib’

  6. ERROR in ./node_modules/web3-eth-accounts/node_modules/eth-lib/lib/bytes.js
    Module not found: Error: Can’t resolve ‘crypto’ in ‘C:\Development\moralis-test\node_modules\web3-eth-accounts\node_modules\eth-lib\lib’

  7. ERROR in ./node_modules/web3-providers-http/lib/index.js
    Module not found: Error: Can’t resolve ‘http’ in ‘C:\Development\moralis-test\node_modules\web3-providers-http\lib’

  8. ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js
    Module not found: Error: Can’t resolve ‘http’ in ‘C:\Development\moralis-test\node_modules\xhr2-cookies\dist’

  9. ERROR in ./node_modules/web3-providers-http/lib/index.js
    Module not found: Error: Can’t resolve ‘https’ in ‘C:\Development\moralis-test\node_modules\web3-providers-http\lib’

  10. ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js
    Module not found: Error: Can’t resolve ‘https’ in ‘C:\Development\moralis-test\node_modules\xhr2-cookies\dist’

  11. ERROR in ./node_modules/xhr2-cookies/dist/xml-http-request.js
    Module not found: Error: Can’t resolve ‘os’ in ‘C:\Development\moralis-test\node_modules\xhr2-cookies\dist’

  12. ERROR in ./node_modules/cipher-base/index.js
    Module not found: Error: Can’t resolve ‘stream’ in ‘C:\Development\moralis-test\node_modules\cipher-base’

  13. ERROR in ./node_modules/keccak/lib/api/shake.js
    Module not found: Error: Can’t resolve ‘stream’ in ‘C:\Development\moralis-test\node_modules\keccak\lib\api’

  14. ERROR in ./node_modules/keccak/lib/api/keccak.js
    Module not found: Error: Can’t resolve ‘stream’ in ‘C:\Development\moralis-test\node_modules\keccak\lib\api’

For more information :smile:

Project structure:

app.component.ts

copy the patch.js file from the angular demo project and add “postinstall”: “node patch.js” to your package.json scripts. This will solve the issue

Thank you, I will give it a go

is it working for you?

Yes my project is working now