Search code examples
reactjsreact-nativenode-modulesnode-uuid

Unable to resolve module util from node_modules\uuidv4\build\lib\uuidv4.js


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?


Solution

  • 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.