Cannot build iOS ngModule error

I am trying to test out my app on iOS and for the life in me I cannot get it to build the app. I can run ionic serve, no problem, I can run ionic run android, no problem, but it will not build the iOS Xcode project. The first set of errors was saying …

Error: Type AddPostPage in /Volumes/SharedFolders/shared_app/src/pages/add-post-page/add-post-page.ts is part of the declarations of 2 modules: AppModule in /Volumes/SharedFolders/shared_app/src/app/app.module.ts and AddPostPageModule in /Volumes/SharedFolders/shared_app/src/pages/add-post-page/add-post-page.module.ts! Please consider moving AddPostPage in /Volumes/SharedFolders/shared_app/src/pages/add-post-page/add-post-page.ts to a higher module that imports AppModule in /Volumes/SharedFolders/shared_app/src/app/app.module.ts and AddPostPageModule in /Volumes/SharedFolders/shared_app/src/pages/add-post-page/add-post-page.module.ts. You can also create a new NgModule that exports and includes AddPostPage in /Volumes/SharedFolders/shared_app/src/pages/add-post-page/add-post-page.ts then import that NgModule in AppModule in /Volumes/SharedFolders/shared_app/src/app/app.module.ts and AddPostPageModule in /Volumes/SharedFolders/shared_app/src/pages/add-post-page/add-post-page.module.ts.

So I tried to remove the add-post-page.module.ts file and run it again, now I get the following error…

Error: /Volumes/SharedFolders/shared_app/src/pages/add-post-page/add-post-page.ts has a @IonicPage decorator, but it does not have a corresponding “NgModule” at /Volumes/SharedFolders/shared_app/src/pages/add-post-page/add-post-page.module.ts

So, if I have the .module.ts file it complains that it’s there, if I remove it it complains that it isn’t there. A side note, I never created any of the .module.ts files. I open the command line and run ionic g page AddPostPage and it puts those .module.ts files in the directory.

How can I build iOS? If I leave the module.ts files it will complain, but it I remove them it will complain. Seems a little paradoxical to me. You can’t have this file, wait the file I said you can’t have isn’t there. Please help, this is driving me nuts. Thank you.

First of all, this is not specific to iOS.

You must decide whether you want to lazily load AddPostPage.

If so, take all mentions of it out of app.module.ts and make all references to it in calls to the navigation system be strings: nav.push("AddPostPage") not nav.push(AddPostPage).

If not, leave it in app.module.ts, delete add-post-page.module.ts, take the IonicPage decorator off of the AddPostPage component, and make all references in calls to the navigation system constructors: the opposite of above.

Finally, in my personal opinion the generators cause more hassle than they generate value, so I just don’t use them at all.

1 Like

Awesome, thank you so much for the help. That makes complete sense.
If I may trouble you for one more small bit of help please…
I was able to get it to build finally, and get into xCode, and get onto my iPad, it was rather exciting. Then I realized I needed to make a change, so I open up my code (the ionic code, not the xCode project), change the URL of a data source that had a typo in it. Head back to the terminal window to build it out again for xCode, type in…

ionic cordova build ios

Hit enter, and boom, errors now. Only it isn’t anything I have seen before this time it is saying…

cp: copyFileSync: could not write to dest file (code=ENOENT):/Volumes/SharedFolders/shared_app/platforms/ios/._2freedom/config.xml

I have no idea why it isn’t there, where it went, or what it even does. It built out great the first time, but now every time I try to build ios it says the same error. Is there something you have to do special after you build for ios and launch in Xcode? I closed out the Xcode project, but still no go. Thank you in advance for any advice you can give with this. The whole building for iOS has been a major headache, I really wish it were all as easy as Android, lol.

I would suggest creating a new topic for your second question.

Thank you for this. Really helped me understand what’s going on.