You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AOT error when referencing components from another project #6059
This is a bug when building with AOT (it builds fine with JIT).
I have two projects. The project A has a (git) dependency on project B. The project B contains a ParentComponent whose template refers to a child component selector (). The project A contains the ChildComponent (with selector ), and a module declaring the two components (ParentComponent and ChildComponent).
The log given by the failure.
ERROR in /home/muriel/Workspace/aot-error/src/$$_gendir/node_modules/aot-error-dep/src/app/parent.component.ngfactory.ts (1,1): Cannot find module '../../../../../$_gendir/app/child.component.ngfactory'.
ERROR in ./src/$$_gendir//aot-error-dep/src/app/parent.component.ngfactory.ts
Module not found: Error: Can't resolve '../../../../../$_gendir/app/child.component.ngfactory' in '/home/muriel/Workspace/aot-error/src/$$_gendir/node_modules/aot-error-dep/src/app'
@ ./src/$$_gendir//aot-error-dep/src/app/parent.component.ngfactory.ts 8:0-81
@ ./src/$$_gendir/app/app.module.ngfactory.ts
@ ./src/main.ts
@ multi ./src/main.ts
Desired functionality.
No error when building AOT, just like the JIT.
I need to have components in an external git project used to be shared with multiple other projects. So I need to be able to have a parent component in another project that the project containing the child component.
@mbail Seems like you are directly referencing the component from another project which doesn't work in AOT. You should create a library project and export Core Module from LibProject. Import the module in your project and use it. Check Angular Material for more: https://github.com/angular/material2
I'm not sure I understand. Can you explain with more details please ?
My project B is not intented to be built with AOT, it is just a project used as container for angular components to share.
It is perfectly possible to declare component from another project B in a module of the project A, but it does not work only if the component refers to a child component existing in A.
Finally, if I make a module in project B declaring the ParentComponent with schemas: [ NO_ERRORS_SCHEMA ] (*)
and import it in project A, it builds with AOT but it does not work at runtime: the child component is not correctly resolved (the html contains the parent's template , but the child template is not displayed).
(*) : I have to put NO_ERRORS_SCHEMA to disable the error :
ERROR in Template parse errors:
'child' is not a known element:
1. If 'child' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("[ERROR ->]<child></child>"): ng:///home/muriel/Workspace/aot-error/node_modules/aot-error-dep/src/app/parent.component.ts.ParentComponent.html@0:0
You're using https://github.com/mbail/aot-error-dep as a dependency, and it really needs to be AOT ready for that to work. You might not want to do it, but for an Angular app to be compiled with AOT all of it's third party NgModules (and whatever else Angular bits) need to support AOT as well.
The CLI doesn't support making third party libs, and there isn't official guidance yet, but there's a guide under review at angular/angular#16486
Activity
sumitarora commentedon Apr 24, 2017
@mbail Seems like you are directly referencing the component from another project which doesn't work in AOT. You should create a library project and export Core Module from LibProject. Import the module in your project and use it. Check Angular Material for more: https://github.com/angular/material2
mbail commentedon Apr 24, 2017
I'm not sure I understand. Can you explain with more details please ?
My project B is not intented to be built with AOT, it is just a project used as container for angular components to share.
It is perfectly possible to declare component from another project B in a module of the project A, but it does not work only if the component refers to a child component existing in A.
Finally, if I make a module in project B declaring the ParentComponent with
schemas: [ NO_ERRORS_SCHEMA ](*)and import it in project A, it builds with AOT but it does not work at runtime: the child component is not correctly resolved (the html contains the parent's template , but the child template is not displayed).
(*) : I have to put NO_ERRORS_SCHEMA to disable the error :
jpguevara commentedon Apr 24, 2017
I did this to depict a different error, but it can be used for what you intent to do.
This will compile the library using AOT and you will be able to consume from the app package
https://github.com/chorew/AngularSample/tree/no-lazy-load
mbail commentedon Apr 25, 2017
Thank you. I was resigned myself to do the same. But it is still a workaround. I would like the AOT builder to handle my case.
filipesilva commentedon May 5, 2017
You're using https://github.com/mbail/aot-error-dep as a dependency, and it really needs to be AOT ready for that to work. You might not want to do it, but for an Angular app to be compiled with AOT all of it's third party NgModules (and whatever else Angular bits) need to support AOT as well.
The CLI doesn't support making third party libs, and there isn't official guidance yet, but there's a guide under review at angular/angular#16486
angular-automatic-lock-bot commentedon Sep 7, 2019
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.