I am facing an issue where I have installed uuid using npm install -g uuid
. However, when I attempt to run the code below:
var uuid = require("uuid");
console.log(uuid.v1());
an error is thrown:
module.js:339
throw err;
^
Error: Cannot find module 'uuid'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (d:\CodingProjects\HTML\TestJavascript.js:16:12)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
When I install the module locally with npm install uuid
, it works without any issues. But what could be causing this difference? How can I make my global packages function properly?
I have even tried downloading it from
Language & Frameworks -> Javascript -> Libraries
, but I still encounter an error if I don't install it locally for each project.
Any assistance on resolving this matter would be highly appreciated.