Ionic 2 RC.0 - error ts2307: cannot find module 'crypto-js'

Hello guys,

Someone has managed to import the crypto-js in ionic version 2 RC.0?
I have this problem: error ts2307: cannot find module ‘crypto-js’

Version 11.alpha is running fine.

Thanks.

Att;
Claudio

1 Like

Solution here;

npm install crypto-js --save
npm install @types/crypto-js

from: import { CryptoJS } from ‘crypto-js’;
to: import * as CryptoJS from ‘crypto-js’;

add file in src project;
declarations.d.ts
with;
declare module ‘crypto-js’;

3 Likes

Do you have a example using AES encrypt? It give me the error that AES is not defined…

image

I am doing like that

window.localStorage.setItem(“utilizador11”, CryptoJS.AES.encrypt(iUtilizador, “--------”));

And have this error

image

===============

Resolved by myself!

Changed this

import * as CryptoJS from ‘crypto-js’;

to

import CryptoJS from ‘crypto-js’;

Now it works!

3 Likes

No problem of import or type, but when I encrypt “haha” with AES, give me “7c4ef905d79f0addb987341fd6f8c89f”.
And when I decypt this Result I obtain nothing !!!

Any help :cry: ? Thanks

My code is :

let confidentMsg: string = CryptoJS.AES.encrypt('haha', "password").ciphertext.toString();
console.log('confidentMsg > ', confidentMsg)

let clearMsg: string = CryptoJS.AES.decrypt('7c4ef905d79f0addb987341fd6f8c89f', "password").toString(CryptoJS.enc.Utf8);
console.log('clearMsg > ', clearMsg);

My ionic info :
******************************************************
Dependency warning - for the CLI to run correctly,
it is highly recommended to install/upgrade the following:
Please install your Cordova CLI to version >=4.2.0 npm install -g cordova
******************************************************

Your system information:
 You have been opted out of telemetry. To change this, run: cordova telemetry on.
6.4.0
Ionic Framework Version: 2.0.0-rc.5
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 1.0.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.9.2
Xcode version: Not installed

I use only.
before:
let confidentMsg: string = CryptoJS.AES.encrypt(‘haha’, “password”).ciphertext.toString();
console.log('confidentMsg > ', confidentMsg)

after:
let confidentMsg: string = CryptoJS.AES.encrypt(‘haha’, “password”).toString();
console.log('confidentMsg > ', confidentMsg)

can you try.

Bye