2

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?

2
  • how are you running the file? node /my/file.js? 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. Commented May 19, 2018 at 14:22

1 Answer 1

3

This 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+ .......... compatible ✔
Firefox 2+ ..... compatible ✔
Safari 3.2+ .... compatible ✔
Chrome 3+ ...... compatible ✔
Opera 10+ ...... compatible ✔

http://requirejs.org/docs/download.html

Add this to your project: download_me

please go through require.js docs.

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

2 Comments

I 'd like to note for you that I was not the one who voted your answer down.
Ok, no worries. :)

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.