Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Library: Error: export 'X' (imported as 'X') was not found in 'my-pkg/my-lib' (possible exports MyLibComponent, MyLibModule, MyLibService)

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.

like image 513
awdorrin Avatar asked Dec 07 '25 17:12

awdorrin


1 Answers

On Apr 8, 2023 at 7:51 JSON Derulo said:

I suspect this could be a caching issue. Did you try clearing the .angular folder of your application project?

After deleting the content of the .angular folder and rebuilding, the errors went away. I have found similar issues with the .angular folder during the past year.

Also, the .angular folder can get quite huge as old libraries are left behind in the .angular cache folders as you update packages over time. I would strongly recommend periodic removal of the .angular folder to refresh the cache and reclaim disk space.

like image 139
awdorrin Avatar answered Dec 09 '25 15:12

awdorrin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!