1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Angular Library: Error: export 'X' (imported as 'X') was not found in 'my-pkg/my-lib'...

Discussão em 'Angular' iniciado por awdorrin, Outubro 14, 2024 às 05:22.

  1. awdorrin

    awdorrin Guest

    I am trying to package a set of classes into an Angular Library. I followed the steps here: https://angular.io/guide/creating-libraries:

    ng new my-pkg --no-create-application
    cd my-pkg
    ng generate library my-lib


    I then removed the generated module, component and service, and added my own classes.

    I added explicit exports in public-api.ts, example:

    export { MyLibServiceFactory } from './lib/my-lib-service-factory';
    export { MyLibService } from './lib/my-lib-service';
    export { MyLibConfiguration } from './lib/my-lib-configuration';


    The library compiles without any errors or warnings. I import it into my app.module.ts with:

    import { MyLibServiceFactory, MyLibConfiguration } from "@my-pkg/my-lib";


    However, when I try to compile I get:

    ./src/app/app.module.ts:51:241-260 - Error: export 'MyLibServiceFactory' (imported as 'MyLibServiceFactory') was not found in '@my-pkg/my-lib' (possible exports: MyLibComponent, MyLibModule, MyLibService)

    ./src/app/app.module.ts:52:15-33 - Error: export 'MyLibConfiguration ' (imported as 'MyLibConfiguration ') was not found in '@my-pkg/my-lib' (possible exports: MyLibComponent, MyLibModule, MyLibService)


    I am pretty convinced I am missing something simple, but I have been searching for about 4 hours now, without any luck.

    I am working with Angular 15 and Typescript 4.9 The library uses some Angular core methods like HttpClient.

    Continue reading...

Compartilhe esta Página