3

I am getting an error in Angular 10 while doing ng build --prod. It works in 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.

This is the file inside 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

This is how I am using this in app.module.ts file

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

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

How can I fix this ?

R15
  • 13,982
  • 14
  • 97
  • 173

2 Answers2

3

This package is not maintained for 3 years, I would recommend using https://www.npmjs.com/package/ngx-pipes#timeago and you can find more details about this issue here https://github.com/AndrewPoyntz/time-ago-pipe/issues/33

this solution worked for some people

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

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

@NgModule({
    declarations: [
        TimeAgoExtendsPipe,
...
salamaashoush
  • 192
  • 1
  • 6
0

Add TimeAgoPipe to exports array of app.module as well.

Nitika
  • 424
  • 2
  • 9