AndrewPoyntz / time-ago-pipe

An Angular pipe for converting a date string into a time ago
MIT License
130 stars 67 forks source link

ERROR in No Pipe decorator found on TimeAgoPipe #22

Open ivissani opened 6 years ago

ivissani commented 6 years ago

I've got the aforementioned error when running ng serve --aot Angular version is 5.1.1.

No error when serving with just ng serve

heintj commented 6 years ago

I am having the same issue, without fix.

safaldas commented 6 years ago

i too am having issue

danduh commented 6 years ago

Same issue, any ideas?

freemanlam commented 6 years ago

same issue

SharmaTushar commented 6 years ago

Issue still persists.

AntonisFK commented 6 years ago

Got this issue when upgrading to angular 6

druvisc commented 6 years ago

Same issue.

EDIT: Workaround for me was to just copy the source code and to create the file in my project.

rvuyyuru1 commented 6 years ago

same issue

jiboune commented 6 years ago

+1

hbarve1 commented 5 years ago

same issue.

maybe this will help, but this is for older version of this lib. https://stackoverflow.com/questions/47119135/cannot-determine-the-module-for-component-angular-5

JonesM87 commented 5 years ago

+1

IshanBhuta commented 5 years ago

Same for me

DejanNemet commented 5 years ago

Same error.

AnilBhandare09 commented 5 years ago

same issue.

ayoubchebbi commented 5 years ago

same issue.

nijat12 commented 5 years ago

Same issue with Angular 6.1.10

jjgriff93 commented 5 years ago

same issue

crufter commented 5 years ago

Same here :(

ayoubchebbi commented 5 years ago

yes

[image: Mailtrack] https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5& Sender notified by Mailtrack https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5& 21/01/19 à 22:33:25

Le lun. 21 janv. 2019 à 19:12, Cruft King notifications@github.com a écrit :

Same here :(

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AndrewPoyntz/time-ago-pipe/issues/22#issuecomment-456159722, or mute the thread https://github.com/notifications/unsubscribe-auth/ARIk3R49t3esDLbNXgXL-leXv8hTS9Xlks5vFgMcgaJpZM4Tzoy4 .

etsraphael commented 5 years ago

Same issue.

I suggest everyone ngx-timeago it's better, I found my solution with this one

tolotrasamuel commented 5 years ago

What is the fix ?

JonesM87 commented 4 years ago

You can fix this by adding the missing decorator, add this line:

@Pipe({ name: 'timeAgo' })

above the export line in the module source code, time-ago.pipe.d.ts

shannon-kay commented 4 years ago

Still seeing this issue with Ang 8, and the above didn't work for me.

ajaysarw commented 4 years ago

I also faced this issue and fixed by @JonesM87's suggestion.

JSX001 commented 4 years ago

still seeing this cant find a workaround.

ng serve - always works, but a save to any source file when it recompiles and I get the error.

strangely, only started happening after I inadvertently upgraded to Angular 9 and then had to uninstall and go back to angular 8.

mikejoseph23 commented 4 years ago

still seeing this cant find a workaround.

ng serve - always works, but a save to any source file when it recompiles and I get the error.

strangely, only started happening after I inadvertently upgraded to Angular 9 and then had to uninstall and go back to angular 8.

Same issue here. I upgraded to Angular 9 yesterday and am getting this error on my local development web server (http://localhost:4200) ... I can run "ng serve" but if I change a file and it recompiles in response to me pressing "save" in my editor, this error appears: image

In order to get going again, I have to kill the process and do a "ng serve" again, which takes a while. I'm probably going to have to comment out TimeAgo code for now until a fix is found. Luckily it's not referenced a whole lot, but would love to be able to reimplement it.

kuldeeps1ngh commented 4 years ago

same issue here, ng serve works fine, but on any change in any file, upon recompilation, this error throws back. Any solution ?

BenjaminPoutriquet35800 commented 4 years ago

Hey guys certainly not best solution but it's work fine. Rewrite pipe class and export it. Something like this :

import { Pipe, PipeTransform, NgZone, ChangeDetectorRef, OnDestroy } from '@angular/core';

@Pipe({
  name: 'timeAgo',
  pure: false
})
export class TimeAgoExtPipe implements PipeTransform, OnDestroy {
  changeDetectorRef: ChangeDetectorRef;
  ngZone: NgZone;
  timer: any;

  constructor(changeDetectorRef: ChangeDetectorRef, ngZone: NgZone) {
    this.changeDetectorRef = changeDetectorRef;
    this.ngZone = ngZone;
  }

  ngOnDestroy() {
    this.removeTimer();
  }

  transform(value: any, args?: any): any {
    this.removeTimer();
    const d = new Date(value);
    const now = new Date();
    const seconds = Math.round(Math.abs((now.getTime() - d.getTime()) / 1000));
    const timeToUpdate = (Number.isNaN(seconds)) ? 1000 : this.getSecondsUntilUpdate(seconds) * 1000;
    this.timer = this.ngZone.runOutsideAngular(() => {
      if (typeof window !== 'undefined') {
        return window.setTimeout(() => {
          this.ngZone.run(() => this.changeDetectorRef.markForCheck());
        }, timeToUpdate);
      }
      return null;
    });
    const minutes = Math.round(Math.abs(seconds / 60));
    const hours = Math.round(Math.abs(minutes / 60));
    const days = Math.round(Math.abs(hours / 24));
    const months = Math.round(Math.abs(days / 30.416));
    const years = Math.round(Math.abs(days / 365));
    if (Number.isNaN(seconds)) {
      return '';
    } else if (seconds <= 45) {
      return 'a few seconds ago';
    } else if (seconds <= 90) {
      return 'a minute ago';
    } else if (minutes <= 45) {
      return minutes + ' minutes ago';
    } else if (minutes <= 90) {
      return 'an hour ago';
    } else if (hours <= 22) {
      return hours + ' hours ago';
    } else if (hours <= 36) {
      return 'a day ago';
    } else if (days <= 25) {
      return days + ' days ago';
    } else if (days <= 45) {
      return 'a month ago';
    } else if (days <= 345) {
      return months + ' months ago';
    } else if (days <= 545) {
      return 'a year ago';
    } else {
      // (days > 545)
      return years + ' years ago';
    }
  }

  removeTimer() {
    if (this.timer) {
      window.clearTimeout(this.timer);
      this.timer = null;
    }
  }

  getSecondsUntilUpdate(seconds) {
    const min = 60;
    const hr = min * 60;
    const day = hr * 24;

    if (seconds < min) {
      // less than 1 min, update every 2 secs
      return 2;
    } else if (seconds < hr) {
      // less than an hour, update every 30 secs
      return 30;
    } else if (seconds < day) {
      // less then a day, update every 5 mins
      return 300;
    } else {
      // update every hour
      return 3600;
    }
  }
}

and in app.module.ts

import { TimeAgoExtPipe } from './_pipes/time-ago-ext.pipe';

finally replace TimeAgo pipe module by yours.