Skip to content

AOT error when referencing components from another project #6059

Closed

Description

@mbail

Bug Report or Feature Request (mark with an x)

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

Versions.

$ ng --version

@angular/cli: 1.0.0
node: 7.8.0
os: linux x64
@angular/common: 4.0.3
@angular/compiler: 4.0.3
@angular/core: 4.0.3
@angular/forms: 4.0.3
@angular/http: 4.0.3
@angular/platform-browser: 4.0.3
@angular/platform-browser-dynamic: 4.0.3
@angular/router: 4.0.3
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.3

Repro steps.

Clone the git project : https://github.com/mbail/aot-error.git
npm install
npm run build (or ng build --aot)

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.

Mention any other details that might be useful.

Activity

  1. sumitarora commented on Apr 24, 2017

    @sumitarora
    Contributor

    @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

  2. mbail commented on Apr 24, 2017

    @mbail
    Author

    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
    
  3. jpguevara commented on Apr 24, 2017

    @jpguevara

    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

  4. mbail commented on Apr 25, 2017

    @mbail
    Author

    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.

  5. filipesilva commented on May 5, 2017

    @filipesilva
    Contributor

    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

  6. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    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.

  7. locked and limited conversation to collaborators on Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions