uuid: Cannot find module 'uuid/v4'

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

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 👍

If code size is a primary consideration for people, there are options:

  1. Stick with uuid@3.4 and the deep-import syntax
  2. Bite the bullet and convert to ES6 imports and a packager that does tree-shaking. (Will yield benefits beyond just pruning uuid code!)
  3. Use a “one-liner” implementation such as https://stackoverflow.com/a/2117523/109538. (Not actually recommending this, but if code footprint is paramount… well… 😆)

@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))

The problem with this change is that it has greater weight when required.

const { v4: uuidV4 } = require('uuid');