1

I want to use npm module "crypto-js" in app.js of truffle_project. But I can't use it.

Directory structure

app.js:

var CryptoJS = require("crypto-js");
// ...

I build app, then I open build/index.html by browser, I get the error on Javascript console of google chrome:

Uncaught Error: Cannot find module 'crypto-js'

I changed to:

var CryptoJS = require("./node_modules/crypto-js");

or:

var CryptoJS = require("../../node_modules/crypto-js");

but I get the same error. I tried absolute path and relative path, I get the error.

How do I do to use crypto-js module in app.js?

P.S. install command:

# pwd 
~/truffle_project
# npm install crypto-js

and the directory structure is default of truffle.

  • Have you installed this module using npm install? – Mikko Ohtamaa Jan 29 '17 at 12:15
  • @MikkoOhtamaa Yes. I did npm install crypto-js . – taishi Jan 29 '17 at 13:42
  • Please edit the question and show your install command and logs, otherwise var CryptoJS = require("crypto-js"); works – Mikko Ohtamaa Jan 29 '17 at 13:43
  • @MikkoOhtamaa I edited. – taishi Jan 29 '17 at 23:44
2

I solved it by myself.

This problem is not truffle side. I solve to use "crypto-js" of client(bower), and index.html :

<script type="text/javascript" src="../bower_components/crypto-js/crypto-js.js"></script>

done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.