32

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.

17 Answers 17

23

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'); 
Sign up to request clarification or add additional context in comments.

1 Comment

is this then simply called like this: uuidv1() ?
20

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

Comments

13

do

 npm install uuid 

And then in your app.js file do

var uuid = require('uuid'); const uuidv1 = require('uuid/v1'); console.log(uuid.v1()); 

Comments

7

There's an error in the most recently versions of 'uuid'. Try to install:

npm install [email protected] 

or with yarn

yarn add [email protected] 

I've got the answer from this tutorial

1 Comment

I can confirm that on my AWS EC2 server I could run 3.4.0 successfully but the latest version 8.x resulted in an error
3

Instead of

const uuidv1 = require('uuid/v1') 

Use this

const uuidv1 = require('uuid'); console.log(uuidv1.v1()) 

1 Comment

Code-only answers are discouraged on Stack Overflow because they don't explain how it solves the problem. Please edit your answer to explain what this code does and how it improves on the other answers this question has, so that it is useful to other users with similar issues.
1

Run this terminal command:

npm install uuid 

This will output something like this:

[email protected] added 454 packages from 181 contributors, removed 144 packages, updated 1399 packages and audited 1862 packages in 712.444s 

next step import this to your js file

import { v8 as uuidv8 } from 'uuid'; 

Comments

1

The error occurs when you import as const uuid= require('uuid/dist/v4');

code: 'ERR_PACKAGE_PATH_NOT_EXPORTED' 

So the new import is

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

which solves the issue. You can refer this link for more information: https://www.npmjs.com/package/uuid.

Comments

1

Sometimes, you just have to save the types which are by default not saved by npm

npm i --save-dev @types/module-name 

Then you can easily import the module however you wish. I faced the same problem in uuid module.It was resolved by this.

Comments

1

If you use Typescript: npm i @types/uuid

If you use Javascript: npm i uuid

Comments

0

When we import:

const uuid = require("uuid"); 

When we call it we need also specify the version:

uuid.v4(); 

Comments

0

Just remove /v1 from the path and try

const uuid = require('uuid'); 

Comments

0

I tried following changes and it works for me.

const uuidV1 = require('uuid').v1; 

Comments

0
  1. npm install uuid --save 
  2. import { v4 as uuidv4 } from 'uuid'; 
  3. Assign which Variable to you want. this is hold on Unique id -

     uuidv4(); 
  4. After that you again Install Packages -

    npm install 
  5. This is method Working 100% in Angular project.

You will Try...!

Comments

0

Add this in tsConfig.json if you are using Angular version 14:

 "angularCompilerOptions": { "types":["uuid"], } 

Comments

0

Firstly, make sure 'uuid' is installed on your system by typing this command in your command prompt/terminal:

npm i uuid --save 

When installed, in your file where you want to create constant 'uuidV1', make sure you are using the right line of code.

Use this:

const uuidV1 = require('uuid').v1; 

Instead of:

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

This const uuidV1 = require('uuid/v1'); line of code worked just fine for quite some time before (it might work for you as well right now); I'm just showing an alternative for it.

Comments

-1

answer is do try this -update your package.json "uuid": "^3.3.2" and npm install its

Comments

-1

Just do:

cd /usr/local/lib/node_modules 

then:

npm prune 

1 Comment

So Reason from how you install npm. Please refer:stackoverflow.com/questions/33707522/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.