1
I have an application written in Angular 6 and there was a need to send a hash to the client. The contractor approved only the use of the library crypto-js
. I did the implementation and everything works correctly on ng serve
, but when making the production build it gives an error.
Procedure performed:
Installation of dependency on Crypto-ts and typings.
npm install crypto-js --save
npm install @types/crypto-js --save-dev
Use of Cryptojs
I make use of the crypto-js
in a service
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 executing the command ng build --prod
Has anyone ever been through it? How could it solve the problem?
Thank you.
vc added the library to the angular.json file?
– Eduardo Vargas
So @Eduardovargas in the tutorials did not mention this, could explain how it is done?
– Hiago Souza
https://github.com/angular/angular-cli/wiki/stories-global-scripts. take a look at this link and try to find the scripts property in your angular.json or angular-cli.json
– Eduardo Vargas
@Eduardovargas tried to add the address ". /node_modules/Crypto-js/core.js" in the angular.json scripts as described and I still receive the same error
– Hiago Souza