time-ago-pipe: doesn't work with angular 9 version

I have an error in console, when try to import TimeAgoPipe and add to module declarations.

So, little “crutch” like that solved my problem

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

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

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

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 40
  • Comments: 19

Most upvoted comments

Same problem with Angular 9.

It does work in Angular 9 with one little modification:

import {Pipe, PipeTransform} from '@angular/core';
import {TimeAgoPipe} from 'time-ago-pipe';

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

  transform(value: string): string {
    return super.transform(value);
  }
}

Note that you have to implement PipeTransform in order to not get compilation error on @Pipe. Not sure why I both have to extend a class which implements an interface AND implement the interface. But this TimeAgo has caused me enough troubles now, so I’m happy enough as long as it is working.

I’m getting this with Angular 10 (in Ionic). The fixes above (including @larsnedb’s one ) don’t help me.

Fine until I run a prod build. If I run ionic build --prod I get the error:

ERROR in node_modules/time-ago-pipe/time-ago.pipe.d.ts:3:22 - error NG6002: Appears in the NgModule.imports of PipesModule, but could not be resolved to an NgModule class.

This likely means that the library (time-ago-pipe) which declares TimeAgoPipe has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library’s authors to see if the library is expected to be compatible with Ivy.

EDIT: I ended up switching to ngx-pipes as it has a timeAgo

It does work in Angular 9 with one little modification:

import {Pipe, PipeTransform} from '@angular/core';
import {TimeAgoPipe} from 'time-ago-pipe';

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

  transform(value: string): string {
    return super.transform(value);
  }
}

Note that you have to implement PipeTransform in order to not get compilation error on @Pipe. Not sure why I both have to extend a class which implements an interface AND implement the interface. But this TimeAgo has caused me enough troubles now, so I’m happy enough as long as it is working.

Hi! the code looks fine, but I still got errors upon compilation 😦

EDIT: I got it just by converting my date to string 😕