I have an application written in Angular 6 and there has been a need to send a hash to the client. The contractor only approved the use of crypto-js
library. I did the implementation and everything works correctly in ng serve
, but when doing the production build it gives an error.
Procedure completed:
Installation of crypto-ts dependency and typings.
npm install crypto-js --save
npm install @types/crypto-js --save-dev
Using CryptoJS
I make use of crypto-js
in service
of Angular. I leave below the two ways I tried to use the library to fix the error.
// Primeira maneira
import * as CryptoJS from 'crypto-js';
console.log(CryptoJS.MD5('minha-string').toString());
// Segunda maneira
import { MD5 } from 'crypto-js';
console.log(MD5('minha-string').toString());
The error returned is Module build failed
. As below:
ERROR in ./node_modules/crypto-js/core.js
Module build failed (from ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js):
The problem only occurs when running the command ng build --prod
Has anyone ever gone through this? How could you solve the problem?
Thank you.