0

A recent update to crypto-js library switches to using native crypto module of the underlying OS, as I understand it.

As a result, my build fails (verbose output below) if I use the updated version, as it seems it is not wired in the default Angular webpack config.

How to make crypto-js find it?

This comment is enlightning, but I don't know enough of the underlying libraries concepts to navigate by myself.

WARNING in ./node_modules/crypto-js/core.js
Module not found: Error: Can't resolve 'crypto' in '/tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto-js'
resolve 'crypto' in '/tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto-js'
  Parsed request is a module
  using description file: /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto-js/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8
        using description file: /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/package.json (relative path: .)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/package.json (relative path: ./crypto)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/crypto doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/crypto.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/crypto.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/crypto.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/crypto.js doesn't exist
            as directory
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/crypto doesn't exist
      /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto-js/node_modules doesn't exist or is not a directory
      /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/node_modules doesn't exist or is not a directory
      /tmp/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules
        using description file: /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/package.json (relative path: ./node_modules/crypto)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto.js doesn't exist
            as directory
              /tmp/build_fa83cfc445ddeaf2cca1c12ae9bcefc8/node_modules/crypto doesn't exist
Qortex
  • 7,087
  • 3
  • 42
  • 59
  • You forgot to include the fail. – kvetis Feb 12 '20 at 13:55
  • oups, thanks, edited – Qortex Feb 12 '20 at 14:42
  • What version of crypto are you using? – kvetis Feb 12 '20 at 15:08
  • Okay, due to this part, seems to be hard to use https://github.com/brix/crypto-js/blob/develop/src/core.js#L25 in a webpack environment. Webpack just sees the `require` there and tries to resolve it. – kvetis Feb 12 '20 at 15:12
  • Does this answer help: https://stackoverflow.com/a/52367183/1956072 ? – kvetis Feb 12 '20 at 15:17
  • Yeah, ended up on [that also](https://github.com/angular/angular-cli/issues/1548#issuecomment-478837014), but I would prefer to stick with standard config. I might just stay on cryptojs v.3.3.0 and that's it. – Qortex Feb 12 '20 at 15:22
  • Yep, it think that's the best solution for now. – kvetis Feb 13 '20 at 13:11
  • 1
    Follow-up on github issue with an interesting suggestion: https://github.com/brix/crypto-js/issues/262#issuecomment-585489317 – Qortex Feb 13 '20 at 13:16

0 Answers0