cannot determine the module for component angular 5

后端 未结 12 2018
太阳男子
太阳男子 2020-12-29 20:39

I\'m getting following error when I build the Angular app using \"ng build --prod\". This is working when I build with Angular 4 and getting error with Angular 5. With Angul

12条回答
  •  滥情空心
    2020-12-29 21:03

    Angular 5 and specifically angular cli 1.5 has default ahead of time compilation turned on and it needs to know module for all components/pipes etc. that it finds in your project folder if you have some components that aren't declared in any module it will throw errors.

    You can either declare TimeAgoPipe in some module:

    @NgModule({
      declarations: [TimeAgoPipe, ...]
    })
    export class AppModule {}// for example can be any other used module
    

    or try running build without ahead of time compilation resulting code will work slower

    ng build --prod --aot=false
    

    third way if you don't use that pipe at all you can add it to excluded files in tsconfig.json

    {
      ...
      "exclude": [ "path/to/unused/component.ts", ... ]
    }
    

提交回复
热议问题