[Ethereum] use crypto-js module in truffle / app.js

nodejstruffle

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.

Best Answer

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.

Related Topic