Skip to content

Multiple apps and shared components fails on --aot #8031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
veke opened this issue Oct 12, 2017 · 3 comments
Closed

Multiple apps and shared components fails on --aot #8031

veke opened this issue Oct 12, 2017 · 3 comments
Assignees

Comments

@veke
Copy link

veke commented Oct 12, 2017

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.4.6
node: 8.5.0
os: darwin x64
@angular/animations: 4.4.4
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4
@angular/forms: 4.4.4
@angular/http: 4.4.4
@angular/platform-browser: 4.4.4
@angular/platform-browser-dynamic: 4.4.4
@angular/router: 4.4.4
@angular/cli: 1.4.6
@angular/compiler-cli: 4.4.4
@angular/language-service: 4.4.4
typescript: 2.3.4

Repro steps.

Create new application and add second application to apps array in angular-cli.json.
Add another main entry that shares components with default main.ts file.
Running ng build or serve with --aot flag produces build error.

The log given by the failure.

ERROR in Error: Type AppComponent in app.component.ts is part of the declarations of 2 modules

Desired functionality.

Using different apps with shared components would resolve excluding mocks from production code and add additional features for each app.

Mention any other details that might be useful.

Example repo: https://github.com/veke/ng-multiple-apps
ng build --aot

@filipesilva
Copy link
Contributor

The error ... is part of the declarations of 2 modules error is a AOT error where you cannot have a component being part of the declaration of two NgModules.

This error happens in your setup because you have two apps that share all the TS files. The files that each app contains are defined in src/tsconfig.app.json. You use the same tsconfig for both, and that tsconfig only excludes test.ts and *.spec.ts files.

The solution is to create separate tsconfig for each app, excluding the files specific to other apps.

  • rename src/tsconfig.app.json to src/tsconfig.test.json, copy src/tsconfig.test.json to src/tsconfig.test2.json.
  • add "main2.ts", "app/app.test.module.ts", to the exclude array of src/tsconfig.test.json
  • add "main.ts", "app/app.module.ts", to the exclude array of src/tsconfig.test2.json
  • update apps in .angular-cli.json to use these tsconfigs (test uses tsconfig.test.json and test2 uses tsconfig.test2.json.

@veke
Copy link
Author

veke commented Oct 16, 2017

Separated tsconfigs and excluding files was the key. Thank you!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants