12

I generated an app using create-react-app and I want to use crypto-js I am getting the following error

crypto.sha256() is not a function

1 Answer 1

26

You gotta install crypto-js using

npm install crypto-js

In your js files, you have to import module you wanna use

import sha256 from 'crypto-js/sha256';

Now you can use those functions

sha256(nonce + message);

You have do define message and nonce before this

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, can you please explain to me why doesn't import * as crypto from crypto-js work?
@RyanDsouza, in-order to do import *, all modules has to be exported. That's not the case with crypto-js if you look at the code for sha256.js, github.com/brix/crypto-js/blob/develop/src/sha256.js. They're just defining a function . Check out my other answer about how export and import works in node stackoverflow.com/questions/21117160/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.