6

I am a beginner in React programming and I was following this tutorial in Youtube: https://youtu.be/hQAHSlTtcmY and everything went well until it was required to install uuid library and after that when I run the page I get an error saying: "Failed to compile.

./src/App.js

Module not found: Can't resolve 'uuid/v4' in 'C:\Users\username\reactnative\src'" so can anyone help me fix this error? And also there are no other errors in the code and it's exactly the same as shown in the video!

2 Answers2

9

I had the same problem learning from the same tutorial from WebDevSimplified.  For me the following worked fine (i.e., with import):

import { v4 as uuidv4 } from 'uuid';

See Hoàng Vũ Tgtt's answer to «Error: Cannot find module 'uuid'» on Stack Overflow.

m19v
  • 191
  • 1
  • 4
6

Install uuid library via node package manager i.e. npm

npm install uuid      

Then import uuidv4 from uuid library

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

Inside function:

  setTodo(prevTodo => {

    return [...prevTodo,{id:uuidv4(), name: name, complete:false}]
  }) 
Jamal
  • 76