Skip to content Skip to sidebar Skip to footer

Node | Require Is Not Defined

Edit : Problem solved using webpack For the needs of an API, I needed to import MD5 and moment. I downloaded the packages using the basic npm install but when I try to import it on

Solution 1:

You're probably seeing this error because require() does not exist in the browser/client-side JavaScript. If you want to use require() in the browser, then you need to use something like require.js

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.

PS: I agree with cptwonton. Please refer to the mentioned post for an in-depth solution with the various options available.


Solution 2:

try this:

const md5 = require ("md5");
const moment = require ("moment");

Solution 3:

require isn't supported in a browser because Node and ES6 have their different module systems. Are you trying to call require in a browser? In that case I suggest you to setup Babel. But if you use node, then try reistalling nodejs.


Post a Comment for "Node | Require Is Not Defined"