0
votes

I'm building a angular module using angular cli. And in another project I'm calling this module.

When I run ng serve, It all works. But when I run ng build --prod I get the following error:

ERROR in ./node_modules/my-module/dist/pagination/pagination.ngfactory.js Module not found: Error: Can't resolve 'pagination' in '/my-web-application/node_modules/my-module/dist/pagination'

ERROR in ./src/app/app.module.ngfactory.js Module not found: Error: Can't resolve 'pagination' in '/my-web-application/src/app'

ERROR in ./src/app/areas/private/users/list/index.ngfactory.js Module not found: Error: Can't resolve 'pagination' in '/my-web-application/src/app/areas/private/users/list'

In my web application, I'm loading my module this way

@NgModule({
  ...
  imports: [
    MyModule
  ],
  ...
  bootstrap: [AppRootComponent]
})
export class AppModule { }

And calling the component module this way

<pagination [data]="pagination"></pagination>

In MyModule, this is how it's configured

@NgModule({
  declarations: [PaginationComponent],
  imports: [
    CommonModule,
  ],
  exports: [PaginationComponent]
})
export class MyModule { }

What could I be doing that make it crash only when ng build --prod?

Angular CLI: 8.3.5
Node: 10.15.0
OS: darwin x64
Angular: 8.2.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.5
@angular-devkit/build-angular     0.803.5
@angular-devkit/build-optimizer   0.803.5
@angular-devkit/build-webpack     0.803.5
@angular-devkit/core              8.3.5
@angular-devkit/schematics        8.3.5
@angular/cdk                      8.2.0
@angular/cli                      8.3.5
@angular/flex-layout              8.0.0-beta.27
@angular/material                 8.2.0
@ngtools/webpack                  8.3.5
@schematics/angular               8.3.5
@schematics/update                0.803.5
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2

https://github.com/angular/angular-cli/issues/15645

2

2 Answers

0
votes

In MyModule add PaginationComponent to exports array:

@NgModule({
  exports: [
    PaginationComponent
  ]
})
export class MyModule {}

Edit:

Also for:

<pagination [data]="pagination"></pagination>

Make sure property pagination is public in the method where you are implementing that code

0
votes

You will need to export MyModule Module too in your AppModule like so:

@NgModule({
  ...
  imports: [
    MyModule
  ],
  exports: [MyModule]
  ...
  bootstrap: [AppRootComponent]
})
export class AppModule { }