ngx-pagination: "ERROR in Ng2PaginationModule is not an NgModule" after compiling succesfully

Angular 2 version: 2.3.1

ng2-pagination version: 2.0.0

Description of issue: After importing the Ng2PaginationModule in my app.module.ts, everything works, but after building (angular-cli@latest) it outputs an error: ERROR in Ng2PaginationModule is not an NgModule

Steps to reproduce: Simply install using NPM and use in your application.

import { Ng2PaginationModule } from 'ng2-pagination';

...

@NgModule({
  imports: [
    BrowserModule,
    Ng2PaginationModule,
    FormsModule,
    HttpModule
  ],
...

Expected result: Everything should compile without errors. Actually, it compiles and outputs all bundle files, but after it’s done it still throws an error, messing with my teamcity build.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 19 (9 by maintainers)

Most upvoted comments

<pagination-controls (pageChange)=“p = $event”></pagination-controls>

export class XComponent { … p: number;

just add p in your typescript, add should be work. (test it on my app with ng cli 1.0.0à ng build --prod

@NYearOldCoder The reason is that ng build does not do the step of compiling your templates into TypeScript, which does happen then you use the --prod flag. Once a template is compiled into a TypeScript class, it becomes apparent that the variable “p” does not exist on the component, leading to the error.

In dev mode (ng build) this compilation step happens dynamically at run-time, and therefore the TypeScript compiler does not get a chance to complain about it.

@NYearOldCoder I just did the followingL

  • downloaded and extracted your zip file
  • ran npm install
  • ran ng build --prod

And got the following error

ERROR in ng:///C:/Development/temp/pagination-test/src/app/list/list.component.html (3,36): Property 'p' does not exist on type 'ListComponent'.
ng:///C:/Development/temp/pagination-test/src/app/list/list.component.html (3,3): Property 'p' does not exist on type 'ListComponent'.

Is this the same error you get? The reason for this error is that in list.component.html template, you refer to a variable “p” which was not defined on the component class. As soon as I add a p = 1; property to the class, everything builds without error.

@Pinank I just tested this:

  • installed Angular CLI (v1.0.0) and created a new project.
  • in that project I installed ngx-pagination (v3.0.0)
  • imported the NgxPaginationModule and used the pipe and component in the app component.
  • ran both ng build --prod and ng build --aot --prod and both of them completed without error.
  • checked in the browser and everything works.

If you can tell me how to reproduce the error that you see, I’ll investigate.