Error: Type X in *.ts is part of the declarations of 2 modules

I’m getting the same error recently. The project was built successfully and released to app store. But when I tried to update it with a defect fix, it failed to build at:
ionic cordova build android --prod --release.

However

ionic cordova build android --dev
built successfully.

If anybody has an idea, please help.

Here is the error msg from : ionic cordova build --prod:

C:\Development\angular2\iinsight>ionic cordova build android --prod
Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser

[08:14:52] build prod started …
[08:14:52] clean started …
[08:14:52] clean finished in 3 ms
[08:14:52] copy started …
[08:14:52] ngc started …
[WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova). Your plugins may
be out of date.

Where is the error message?

Here is the full error msg:
C:\Development\angular2\iinsight>ionic cordova build android --prod
Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser

[08:14:52] build prod started …
[08:14:52] clean started …
[08:14:52] clean finished in 3 ms
[08:14:52] copy started …
[08:14:52] ngc started …
[WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova). Your plugins may
be out of date.
Error: Type SocialAnxietySeeDoctorPage in C:/Development/angular2/iinsight/src/pages/social-anxiety-see-doctor/social-anxiety-see-doctor.ts is part of the declarations of 2 modules: AppModule in C:/Development/angular2/iinsight/src/app/app.module.ts and SocialAnxietySeeDoctorPageModule in C:/Development/angular2/iinsight/src/pages/social-anxiety-see-doctor/social-anxiety-see-doctor.module.ts! Please consider moving SocialAnxietySeeDoctorPage in C:/Development/angular2/iinsight/src/pages/social-anxiety-see-doctor/social-anxiety-see-doctor.ts to a higher module that imports AppModule in C:/Development/angular2/iinsight/src/app/app.module.ts and SocialAnxietySeeDoctorPageModule in C:/Development/angular2/iinsight/src/pages/social-anxiety-see-doctor/social-anxiety-see-doctor.module.ts. You can also create a new NgModule that exports and includes SocialAnxietySeeDoctorPage in C:/Development/angular2/iinsight/src/pages/social-anxiety-see-doctor/social-anxiety-see-doctor.ts then import that NgModule in AppModule in C:/Development/angular2/iinsight/src/app/app.module.ts and SocialAnxietySeeDoctorPageModule in C:/Development/angular2/iinsight/src/pages/social-anxiety-see-doctor/social-anxiety-see-doctor.module.ts.

Please edit your post and use the </> button above the post input field to format your code or error message or wrap it in ``` (“code fences”) manually. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.[quote=“iInsight, post:3, topic:95497”]
Here is the full error msg:
[/quote]

Yes, which is totally different from the topic you replied to - I moved this to its own topic then.

The reason of and solution to the problem is in the error message by the way…

Thanks, it resolved. It turns out this cause:
“ionic cordova generate” command generate a “module.ts” file with .html/.ts/.scss file. My project is not using .module.ts file, removing it from project, project will build successfully.

1 Like

In updated Ionic script when you add pages with the cli then you don’t need to add page imports in app.module.ts file. When i removed imports from app.module.ts file the problem was gone.

hi when i am removing my module.ts file from the project

following error is throwing

[19:08:14] deeplinks started …
Error: C:\xampp\htdocs\ionic\hair\src\pages\home1\home1.ts has a **@nicPage deco
rator, but it does not have a corresponding “NgModule” at C:\xampp\htdocs\ionic
hair\src\pages\home1\home1.module.ts
at new BuildError (C:\xampp\htdocs\ionic\hair\node_modules@ionic\app-script
s\dist\util\errors.js:16:28)
at C:\xampp\htdocs\ionic\hair\node_modules@ionic\app-scripts\dist\deep-link
ing.js:57:21