1

A warning message shows up when a for loop is used inside of a subscription (when I delete the for loop, the warning dissapear). I was trying to convert a Timestamp from SQL into a number readable for angular, i find a workaround but a warning appears

import { stringify } from '@angular/compiler/src/util';

getUserTasks() {
    this.tasksSubscription = this.userService.getUserTasks(3).subscribe(tasks => {
      this.tasks = tasks;
      for (var ta of this.tasks) {
        let str = ta.startDate.split("[");
        let time = new Date(str[0]);
        ta.startDate = stringify(time.getTime());
      }
      this.TaskDataSource.data = this.tasks;
      this.isLoading = false;
    }
    );
  }

WARNING :

WARNING in ./node_modules/@angular/compiler/src/util.js 10:24-31

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Community
  • 1
  • 1
FTello31
  • 51
  • 1
  • 10

2 Answers2

1

I cannot see the rest of the code, but usually that warning is prompted when you are not importing something correctly. I see you are using the stringify function inside of the for loop, so it could be because of that. Could you share the import line for the stringify function?

David G.
  • 1,255
  • 9
  • 16
  • import { stringify } from '@angular/compiler/src/util'; – FTello31 Oct 22 '19 at 18:59
  • 2
    That is the problem. You should never import from the source folder in an angular dependency. As a matter of fact, I think that function is not even exported as public API, so you shouldn't be using it at all. Looking back at your code, you use it to parse a timestamp to string, this should do exactly the same thing: `ta.startDate = time.getTime().toString();` And get you rid of that warning. – David G. Oct 22 '19 at 20:26
0

Yes, I had the same issue importing the stringify and removing it fixed the error.

user1419261
  • 829
  • 8
  • 5