Crypto-js implementation

I am trying to implement crypto-js with Ionic 2.

I have done the following:

npm install crypto-js
typings install dt~crypto-js --global --save

My index.d.ts now contains:

/// <reference path="globals/crypto-js/index.d.ts" />

A crypto-js folder has been created under ./typings/global

I then try the following code:

declare var require: any;
import * as CryptoJS from 'crypto-js';

...

private CryptoJS: any;

    constructor() {
        this.CryptoJS = require("crypto-js");
    }

    test() {
       alert(this.CryptoJS);
    }

As soon as I try reference this.CryptoJS (i.e alert(this.CryptoJS)) the app crashes.

I am doing something wrong in the way I import the crypto-js libraries. Please can anyone advise?

Thanks

So just a note, the way forward for using types is to use @types from npm

https://www.npmjs.com/package/@types/cryptojs

1 Like

I run:

>npm install --save @types/cryptojs
npm WARN package.json theWhoZoo@ No repository field.
npm WARN package.json theWhoZoo@ No README data
npm WARN package.json theWhoZoo@ No license field.
@types/cryptojs@3.1.29 node_modules\@types\cryptojs

How do I import CryptoJS in the code?

Thanks

For more details: