Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 setTimeout Module not found: Error: Can't resolve 'timers'

I have a problem. I want to use setTimeout in angular to call a function after 2 second but I get this:

ERROR: Module not found: Error: Can't resolve 'timers'; this is my function:

login(user) {
  console.log(user.value);
  this.loginService.loginUser(user.value);
  // this.user = this.loginService.getUser();
  setTimeout(() => {
    this.user = this.loginService.getUser();
  }, 2000);
  if (this.user === undefined) {
     console.log('username or password incorrect');
  } else {
    console.log(this.user);
    this.navbar.connectComps(this.user);
    this.navbar.getCheck();
  }
}

Please tell me what should I do to solve this issue.

like image 765
Ciprian Avatar asked Jun 01 '18 22:06

Ciprian


1 Answers

I got the same error when I used setTimeout. turns out angular added the following line without me realizing it. Once I removed it, everything started to work again.

// remove this import
import { setTimeout } from 'timers';
like image 108
Tanvir Ather Avatar answered Oct 22 '22 23:10

Tanvir Ather