微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在 NgModule 中声明“TimeAgoPipe”,因为它不是当前编译的一部分

如何解决无法在 NgModule 中声明“TimeAgoPipe”,因为它不是当前编译的一部分

我在执行 Angular 10 时在 ng build --prod 中遇到错误。它适用于 ng build

ERROR in src/app/app.module.ts:44:5 - error NG6001: Cannot declare 'TimeAgoPipe' in an NgModule as it's not a part of the current compilation.

44     TimeAgoPipe,~~~~~~~~~~~

  node_modules/time-ago-pipe/time-ago.pipe.d.ts:3:22
    3 export declare class TimeAgoPipe implements PipeTransform,OnDestroy {
                           ~~~~~~~~~~~
    'TimeAgoPipe' is declared here.

这是node_modules/time-ago-pipe/time-ago.pipe.d.ts里面的文件

import { PipeTransform,ngzone,ChangeDetectorRef,OnDestroy } from "@angular/core";
import * as ɵngcc0 from '@angular/core';
export declare class TimeAgoPipe implements PipeTransform,OnDestroy {
    private changeDetectorRef;
    private ngzone;
    private timer;
    constructor(changeDetectorRef: ChangeDetectorRef,ngzone: ngzone);
    transform(value: string): string;
    ngOnDestroy(): void;
    private removeTimer();
    private getSecondsUntilUpdate(seconds);
    static ɵfac: ɵngcc0.ɵɵFactoryDef<TimeAgoPipe,never>;
    static ɵpipe: ɵngcc0.ɵɵPipeDefWithMeta<TimeAgoPipe,"timeAgo">;
}

//# sourceMappingURL=time-ago.pipe.d.ts.map

这就是我在 app.module.ts 文件中使用它的方式

import { NgModule } from '@angular/core';
import {TimeAgoPipe} from 'time-ago-pipe';

@NgModule({
  declarations: [
    TimeAgoPipe
  ],imports: [
    FormsModule,],entryComponents: [LastseenDevicesComponent],bootstrap: [ AppComponent ],})
export class AppModule { }

我该如何解决这个问题?

解决方法

此软件包已 3 年未维护,我建议使用 https://www.npmjs.com/package/ngx-pipes#timeago,您可以在此处找到有关此问题的更多详细信息 https://github.com/AndrewPoyntz/time-ago-pipe/issues/33

此解决方案适用于某些人

...
import { TimeAgoPipe } from 'time-ago-pipe';

@Pipe({
    name: 'timeAgo',pure: false
})
export class TimeAgoExtendsPipe extends TimeAgoPipe {}

@NgModule({
    declarations: [
        TimeAgoExtendsPipe,...
,

也将 TimeAgoPipe 添加到 exportsapp.module 数组中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?