Ionic generate page creates a page.module.ts, and now I get 'Type X is part of the declarations...' errors

What I did was generate a page using the ionic generate p pagename, then edit app.module.ts to include the new page class, but then I get these errors:

Error: Type DrBio in /src/pages/dr-bio/dr-bio.ts is part of the declarations of 2 
            modules: AppModule in /src/app/app.module.ts and DrBioModule in 
            /src/pages/dr-bio/dr-bio.module.ts! Please consider moving DrBio in 
            /src/pages/dr-bio/dr-bio.ts to a higher module that imports AppModule in 
            /src/app/app.module.ts and DrBioModule in 
            /src/pages/dr-bio/dr-bio.module.ts. You can also create a new NgModule that 
            exports and includes DrBio in /src/pages/dr-bio/dr-bio.ts then import that 
            NgModule in AppModule in /src/app/app.module.ts and DrBioModule in 
            /src/pages/dr-bio/dr-bio.module.ts. 

And I’m not sure how to include this module into my project now. The quick fix is to delete dr-bio.module.ts and remove the @IonicPage() declaration from dr-bio.ts, but I’m not positive that follows best practices for pages now.

It’s unclear what best practices are for pages at the moment.

If you’re wanting to use lazy loading, then remove the import from your app.module.ts.

If you don’t (which is likely best for now, depending on your app set-up), then delete the dr-bio.module.ts file and remove the @IonicPage decorator.

1 Like