Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM: Cannot find module 'uuid'

Tags:

I have this message when i try to use npm:

> $ npm module.js:472     throw err;     ^  Error: Cannot found module 'uuid'     at Function.Module._resolveFilename (module.js:470:15)     at Function.Module._load (module.ks:418:25)     at Module.require (module.js:498:17)     at require (internal/module.js:20:19)     at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/metrics.js:10:12)     at Module._compile (module.js:571:32)     at Object.Module._extensions..js (module.js:580:10)     at Module.load (module.js:488:32)     at tryModuleLoad (module.js:447:12)     at Function.Module._load (module.js:439:3) 

I tried to uninstall reinstall with brew but without success.

like image 267
Hamza Boudra Avatar asked May 09 '17 08:05

Hamza Boudra


People also ask

Can not find module uuid?

To solve the error "Cannot find module 'uuid'", make sure to install the uuid package by opening your terminal in your project's root directory and running the following command: npm i uuid . If you use TypeScript, install the typings by running npm i -D @types/uuid . Copied!

Can't resolve uuid v4 react JS?

This error happens because of the file structure in node_modules/uuid, if you look there is no longer a uuidv4 to import and instead they export a v4. You could change all the places where the developers wrote uuidv4 to v4 but using the { this as that } syntax you don't have to rewrite a bunch of code.

What is uuid npm?

The uuid, or universally unique identifier, npm package is a secure way to generate cryptographically strong unique identifiers with Node. js that doesn't require a large amount of code.


2 Answers

You might have seen the error because of this

const uuidv1 = require('uuid/v1'); 

try to replace it with this one

const { v1: uuidv1 } = require('uuid'); 
like image 81
Hassan El khalifte Avatar answered Oct 13 '22 08:10

Hassan El khalifte


You can try (ECMAScript Module syntax)

import { v1 as uuidv1 } from 'uuid'; console.log(uuidv1()); //=> f68f7b70-9606-11ea-9ccc-fbd3ee221c8f 

With v4

import { v4 as uuidv4 } from 'uuid'; uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' 

for more: https://www.npmjs.com/package/uuid

like image 42
Hoàng Vũ Tgtt Avatar answered Oct 13 '22 08:10

Hoàng Vũ Tgtt