Hi,
I install uuid module on my Windows 10 64bit with WebStorm and NodeJS 8.8.1 but when I require the module I get this error:
error: uncaughtException: Cannot find module 'uuid/v4'
Any idea?
Thanks
Hello DEK4, in a shell within your project source folder, could you run npm ls | grep uuid and paste the output of this ?

So great, it's a direct dependency of your project and that's the latest version.
Now, could you execute console.log(require('uuid')); from a test node file ?
ls <project folder>/node_modules/uuid to confirm uuid is installed locally:
kieffer@MacBook-Pro-3$ ls -l node_modules/uuid/
total 72
-rw-r--r-- 1 kieffer staff 169 Nov 17 2016 AUTHORS
-rw-r--r-- 1 kieffer staff 626 Nov 28 2016 HISTORY.md
-rw-r--r-- 1 kieffer staff 1109 Nov 17 2016 LICENSE.md
-rw-r--r-- 1 kieffer staff 4644 Nov 28 2016 README.md
drwxr-xr-x 3 kieffer staff 102 Nov 15 09:03 bin
-rw-r--r-- 1 kieffer staff 120 Nov 28 2016 index.js
drwxr-xr-x 5 kieffer staff 170 Nov 15 09:02 lib
-rw-r--r-- 1 kieffer staff 1775 Nov 15 09:03 package.json
drwxr-xr-x 4 kieffer staff 136 Nov 15 09:02 test
-rw-r--r-- 1 kieffer staff 3235 Nov 28 2016 v1.js
-rw-r--r-- 1 kieffer staff 679 Nov 28 2016 v4.js
Also, try installing into a new, empty directory. This may be an issue with your project configuration.
kieffer@MacBook-Pro-3$ cd /tmp
kieffer@MacBook-Pro-3$ mkdir work
kieffer@MacBook-Pro-3$ cd work
kieffer@MacBook-Pro-3$ ls -F
kieffer@MacBook-Pro-3$ npm i uuid
npm WARN saveError ENOENT: no such file or directory, open '/private/tmp/work/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/private/tmp/work/package.json'
npm WARN work No description
npm WARN work No repository field.
npm WARN work No README data
npm WARN work No license field.
+ [email protected]
added 1 package in 1.003s
kieffer@MacBook-Pro-3$ node -e "console.log(require('uuid/v4'))"
[Function: v4]
The global install also doesn't work
I'm using node v8.9.2
@dsouzadyn Are you trying to require('mime') when it's installed globally? Node discourages this practice. Any require()ed module should be installed locally. Global installs should be reserved for utilities run from the command line.
If you really want to require the global installed version, set your NODE_PATH property accordingly.
No response from @anchnk. Closing
Just ran into this issue on my computer, it was because I was using the newer version of the library than my code was written for.
The original code was
const uuidV4 = require('uuid/v4')
Newer versions of this library requires it to be
const { v4: uuidV4 } = require('uuid');
Hope this helps anyone else searching in the future 馃憤
The problem with this change is that it has greater weight when required.
const { v4: uuidV4 } = require('uuid');
@victorhcortes Not significant in node. Bundlers are able to treeshake unused modules. Though you have to use es modules syntax. Commonjs is not reliable and does not work in a lot of cases.
Commonjs tree shaking is not reliable and does not work in a lot of cases.
FTFY. (... to clarify that CommonJS works fine as a whole. It's only when it comes to tree-shaking - unused code removal - that it becomes problematic.)
@victorhcortes: As the person responsible for the previous incarnation of uuid that allowed for deep imports, I'll just chime in to say this was a much-needed change. The deep-import solution avoided the need for tree-shaking but was problematic when it came to support in some packager tools (Angular, specifically) and CDNs.
@TrySound By accumulating this cost with other dependencies you will know how heavy it can be.
@broofa I understand the point that was necessary to maintain compatibility and avoid problems.
But if I highlight that the change is much greater.
const uuidV4 = require ('uuid/v4'); //1.9K (gzipped: 818) const { v4: uuidV4 } = require ('uuid'); //7.9K (gzipped: 3.3K))
FTFY
Right, I meant this in tree-shaking context.
By accumulating this cost with other dependencies you will know how heavy it can be.
Yes, I know. This is why the change was considered carefully. There is not cost for bundlers and it's not significant for node as reading from disk even large scripts is fast enough. Memory usage is a problem of script execution not the size.
We have a lot of really bloated libraries like lodash which is used in three forms (lodash.*, lodash/*, require('lodash')), btw sometimes even in the same project.
If code size is a primary consideration for people, there are options:
[email protected] and the deep-import syntax@corteshvictor thanks your solutions works for me
Thanks people it solved my problem.
Most helpful comment
Just ran into this issue on my computer, it was because I was using the newer version of the library than my code was written for.
The original code was
Newer versions of this library requires it to be
Hope this helps anyone else searching in the future 馃憤