在执行ng build --prod
时,Angular 10
中出现错误。它在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
添加到app.module
的exports
数组中。