No npm global module required

I have the following problem. I install uuid with npm install -g uuid. When I try to run the following code:

var uuid = require("uuid");
console.log(uuid.v1());

an exception 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)

If I install the module locally with npm install uuid, it works fine. But why? What should I do to make my global packages work? I tried to download it from Language & Frameworks -> Javascript -> Libraries, but I still get an exception if I do not install it locally for my project.

Thanks in advance.

+3
source share
2 answers

The reason is how the npmpackages install.

npm install -g <package>, npm <package> . , , , Gulp:

$ npm install -g gulp
$ cd path/to/project
$ gulp

, .

, , .. . . npm: . npm install -g .

$ npm install uuid

, , foo, foo/node_modules uuid. .js foo ( ), uuid, .


WebStorm: Language & Frameworks → Javascript → Libraries npm, . WebStorm .

+4

, , , . ( ).

, "npm link uui" , . , , () , , .

, , , "npm link".

+2

Source: https://habr.com/ru/post/1017100/


All Articles