I have recently updated my angular app from V8 to V9 using this guide provided by the official Angular site. I followed all the steps from the guide and the app was successfully updated, but now when I try to build, I get loads of errors related to pipes directives and even components that I am using in my templates.
Here's one example for errors on pipes:
Cannot declare 'TimeAgoPipe' in an NgModule as it's not a part of the current compilation.
Another example of errors on directives:
Can't bind to 'ngModel' since it isn't a known property of 'input'
This code worked perfectly fine on Angular 8:
<input required name="password" class="form-control mr-sm-2" type="password" placeholder="Password" [(ngModel)]="model.password"/>
It can't even find components that I have created even though they have been declared in the app.module.ts
file. It's giving me this error:
'app-nav' is not a known element:
If 'app-nav' is an Angular component, then verify that it is part of this module.
If 'app-nav' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
Here's my app.module.ts
file where everything it is not finding has been included:
import { BrowserModule, HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import { NgModule, Injectable } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { JwtModule } from '@auth0/angular-jwt';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BsDropdownModule, PaginationModule, ButtonsModule } from 'ngx-bootstrap';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { TabsModule } from 'ngx-bootstrap/tabs';
import { NgxGalleryModule } from 'ngx-gallery';
import { FileUploadModule } from 'ng2-file-upload';
import { TimeAgoPipe } from 'time-ago-pipe';
import { CommonModule, DatePipe } from '@angular/common';
import { AppComponent } from './app.component';
import { NavComponent } from './nav/nav.component';
import { AuthService } from './_services/auth.service';
import { HomeComponent } from './home/home.component';
import { RegisterComponent } from './register/register.component';
import { ErrorInterceptorProvider } from './_services/error.interceptor';
import { MembersListComponent } from './members/members-list/members-list.component';
import { ListsComponent } from './lists/lists.component';
import { MessagesComponent } from './messages/messages.component';
import { appRoutes } from './routes';
import { MemberCardComponent } from './members/member-card/member-card.component';
import { environment } from 'src/environments/environment';
import { MemberDetailComponent } from './members/member-detail/member-detail.component';
import { UserService } from './_services/user.service';
import { AlertifyService } from './_services/alertify.service';
import { AuthGuard } from './_guards/auth.guard';
import { MemberDetailResolver } from './_resolvers/member-detail.resolver';
import { MemberListResolver } from './_resolvers/member-list.resolver';
import { MemberEditComponent } from './members/member-edit/member-edit.component';
import { MemberEditResolver } from './_resolvers/member-edit.resolver';
import { PreventUsavedChangesGuard } from './_guards/prevent-usaved-changes.guard';
import { DetailCardContentComponent } from './members/detail-card-content/detail-card-content.component';
import { PhotoEditorComponent } from './members/photo-editor/photo-editor.component';
export function tokenGetter() {
return localStorage.getItem(environment.authTokenName);
}
@Injectable()
export class CustomHammerConfig extends HammerGestureConfig {
overrides = {
pinch: { enable: false },
rotate: { enable: false }
};
}
@NgModule({
declarations: [
AppComponent,
NavComponent,
HomeComponent,
RegisterComponent,
MembersListComponent,
ListsComponent,
MessagesComponent,
MemberCardComponent,
MemberDetailComponent,
MemberEditComponent,
DetailCardContentComponent,
PhotoEditorComponent,
TimeAgoPipe,
DatePipe
],
imports: [
BrowserModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
CommonModule,
BsDropdownModule.forRoot(),
TabsModule.forRoot(),
BsDatepickerModule.forRoot(),
ButtonsModule.forRoot(),
BrowserAnimationsModule,
RouterModule.forRoot(appRoutes),
PaginationModule.forRoot(),
NgxGalleryModule,
FileUploadModule,
JwtModule.forRoot({
config: {
tokenGetter,
whitelistedDomains: environment.routesWithAuthorization,
blacklistedRoutes: environment.routesWithoutAuthorization
}
})
],
providers: [
AuthService,
UserService,
AlertifyService,
AuthGuard,
PreventUsavedChangesGuard,
MemberDetailResolver,
MemberListResolver,
MemberEditResolver,
ErrorInterceptorProvider,
{ provide: HAMMER_GESTURE_CONFIG, useClass: CustomHammerConfig }
],
bootstrap: [AppComponent]
})
export class AppModule {}
The solution suggested by Instinct and from https://github.com/AndrewPoyntz/time-ago-pipe/issues/33 works. You have to remember to disable AOT compilation on angular.json though
It looks like this module isn't updated for Angular 9. I found a workaround here
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,
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With