WARNING in ./node_modules/@angular/compiler/src/util.js 10:24-31 Critical dependency: require function is used in a way which dependencies

WARNING in ./node_modules/@angular/compiler/src/util.js 10:24-31 Critical dependency: require function is used in a way in which dependencies

在订阅内使用 for 循环时会出现警告消息(当我删除 for 循环时,警告消失)。我试图将时间戳从 SQL 转换为 angular 可读的数字,我找到了解决方法,但出现警告

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

我看不到其余代码,但通常在您未正确导入某些内容时会提示该警告。 我看到您在 for 循环中使用了 stringify 函数,所以可能是因为这个原因。您可以分享 stringify 函数的导入行吗?

是的,我在导入 stringify 并删除它时遇到了同样的问题修复了错误。