1

There are some questions with this title but I have. tried every solution in them but I'm unable to resolve this.

I've just started learning React-Native and I'm getting this error:

enter image description here

I've tried the steps mentioned in this red box. I've tried deleting node_modules folder and then installing it again. I've also changed "uuidv4": "^5.0.1" version and installed npm install again. but it didn't work. The code where I've used uuidv4 is:

const [items, setItems] = useState([
    { id: uuid(), text: 'Milk' },
    { id: uuid(), text: 'Eggs' },
    { id: uuid(), text: 'Bread' },
    { id: uuid(), text: 'Juice' }
]);

I've imported it as import { uuid } from 'uuidv4';

Any help?

Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116

4 Answers4

10

After searching for hours and hours this is how I solved the issue. The problem is not with uuidv4 it's with util. All I did was to install npm install util and uuidv4 is now working.

Here is the link: https://www.npmjs.com/package/util of the package. Install this and it'll at least resolve this issue.

Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116
5

With uuidv4@6.5.12 you can also:

import { v4 as uuid } from 'uuid';

This gets rid of the utils dependency error without needing to install utils.

Cosmin Leferman
  • 128
  • 1
  • 6
0

I think it's been exported as default and you need to try this:

import uuid from "uuidv4";
Taghi Khavari
  • 6,272
  • 3
  • 15
  • 32
0

its not problem of uuidv4. uuidv4 use util package most of time this package is not install. So Solution of this problem is that first install util package than install than install uuidv4.

Solution:

npm install util

than install

npm install uuidv4