So, I'm trying to use node modules with JavaScript and for that, I need to load the modules with "require", so I installed Require.js like so:
npm i requirejs
This is my code:
var ecurve = require('ecurve') ;
var BigInteger = require('bigi')
var AES = require("crypto-js/aes");
var SHA256 = require("crypto-js/sha256");
var CryptoJS = require("crypto-js");
However, I always get this error:
require is not defined
I've tried Browserify and solved the problem but I need another solution without Browserify. Any ideas?
So, I'm trying to use node modules with JavaScript and for that, I need to load the modules with "require", so I installed Require.js like so:
npm i requirejs
This is my code:
var ecurve = require('ecurve') ;
var BigInteger = require('bigi')
var AES = require("crypto-js/aes");
var SHA256 = require("crypto-js/sha256");
var CryptoJS = require("crypto-js");
However, I always get this error:
require is not defined
I've tried Browserify and solved the problem but I need another solution without Browserify. Any ideas?
Share Improve this question edited May 19, 2018 at 14:25 Edric 26.9k13 gold badges87 silver badges95 bronze badges asked May 19, 2018 at 14:15 Az EmnaAz Emna 5352 gold badges12 silver badges26 bronze badges 2-
how are you running the file?
node /my/file.js
? – Get Off My Lawn Commented May 19, 2018 at 14:21 -
you don't need
requirejs
when running a node application.require
is built into node, so it sounds like you are not running the file properly. – Get Off My Lawn Commented May 19, 2018 at 14:22
1 Answer
Reset to default 3This would help you:
RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.
IE 6+ .......... patible ✔ Firefox 2+ ..... patible ✔ Safari 3.2+ .... patible ✔ Chrome 3+ ...... patible ✔ Opera 10+ ...... patible ✔
http://requirejs/docs/download.html
Add this to your project: download_me
please go through require.js docs.