angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.78k stars 11.98k forks source link

declare one component in two apps module and build on prod report error #7669

Closed yokots closed 7 years ago

yokots commented 7 years ago

Bug Report or Feature Request (mark with an x)

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

Versions.

macOS Sierra: 10.12.6 cli: 1.4.1 angular: 4.3.6 node: 8.4.0 npm: 5.4.1

Repro steps.

I use a component between two app, app0 and app1, when I build app1 with --prod --build-optimizer, it report an error that Type XComponent is part of the declarations of 2 modules. If build app1 just use ng build --app=1 without other arguments, it will build success. I know that a component can't declare on 2 modules in one app, it should declare at shared module, but this is in two apps, I think it should not report the error. Now I export XXComponent extend XComponent like this, and I import XComponent at app0, import XXComponent at app1 to cheat angular. I hope get some help about this.

The log given by the failure.

Desired functionality.

Mention any other details that might be useful.

hansl commented 7 years ago

Are you including files from app 1 in the tsconfig.json for app 0? That might explain the message.

yokots commented 7 years ago

@hansl All the files are in src, src/app0 and src/app1, and the XComponent declare at app0 XFeature module, how to configure the tsconfig.json shuold me?

filipesilva commented 7 years ago

@yokots you can configure the files, include and exclude properties of a tsconfig file to control which ts files are included in that app compilation. In your case you will to exclude modules from app1 in app0 and vice versa.

Remember to edit the right tsconfig, the default one is src/tsconfig.app.json but you should have one of each of your apps.

You can read more about tsconfig files here: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html.

angular-automatic-lock-bot[bot] commented 5 years ago

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.