Angular: import based on index.ts causes: "ERROR TypeError: Cannot read properties of...

Discussão em 'Angular' iniciado por Dalua Lama, Junho 15, 2025.

  1. Dalua Lama

    Dalua Lama Guest

    In my Angular project I have multiple shared components. My relevant folder structure is:

    src
    app
    shared
    components
    _
    ...
    confirmation (folder with the confirmation component)
    notification (folder with the notification component)
    ...
    index.ts



    index.ts contains explicit export of different shared components like:

    export ...
    export { ConfirmationComponent } from "./_/confirmation/confirmation.component";
    export { NotificationComponent } from "./_/notification/notification.component";
    export ...


    If in a specific component using both shared components ConfirmationComponent and NotificationComponent I import those two components this way:

    import { ConfirmationComponent } from "../../../shared/components/_/confirmation/confirmation.component";
    import { NotificationComponent } from "../../../shared/components/_/notification/notification.component";


    ... everything is fine and working OK. However, if I do it like this (which compiles well, because of the index.ts):

    import { ConfirmationComponent } from "../../../shared/components/_/confirmation/confirmation.component";
    import { NotificationComponent } from "../../../shared/components";


    ... then I get in a very different(!) context of the App (not even in the context of this particular component) the ERROR:

    ERROR TypeError: Cannot read properties of undefined (reading 'ɵcmp')
    at getComponentDef (core.mjs:2529:12)
    at extractDirectiveDef (core.mjs:2418:12)
    at core.mjs:2592:21
    at Array.map (<anonymous>)
    at core.mjs:2592:10
    at createTView (core.mjs:11394:63)
    at getOrCreateComponentTView (core.mjs:11343:28)
    at addComponentLogic (core.mjs:12096:19)
    at instantiateAllDirectives (core.mjs:11898:9)
    at createDirectivesInstances (core.mjs:11306:5)


    What am I missing here? Why is that?

    It took me some considerable time to get even to this point, as the error occurred during "cleaning up" the app structure, imports etc. So suddenly I've got this ERROR. I wasn't obvious which particular change caused it.

    Continue reading...

Compartilhe esta Página