I'm currently trying to upgrade my Angular 2.something project to the latest version. I had a custom angular.config file so i could build 2 app's consuming the same component 'library'. But then the epic release of Angular 6 arrived with real Angular libraries! But now i am stuck (again) trying to refactor my project to this new version.
I've come as far as building a component library (named 'core') into a DIST folder. Even Typescript is okay with this library. But when i try to build my web-app Angular CLI starts complaining that it can't find the module 'core'.
The following code snippet is the public_api.d.ts in the folder dist/core:
export { WdCoreModule } from './lib/wd-core.module';
export { wdApi } from './lib/core/wd.service';
export { ProcessTokenComponent } from './lib/core/process-token.component';
export { GroupByPipe } from './lib/core/group-by.pipe';
export { AvatarComponent } from './lib/avatar/avatar.component';
export { GameElementsModule } from './lib/game-elements/game-elements.module';
export { AchievementsComponent } from './lib/game-elements/achievements/achievements.component';
export { ModalComponentComponent } from './lib/modal-component/modal-component.component';
export { BaseModalService, BaseModalComponent } from './lib/core/basemodal.service';
export { NavMenuComponent } from './lib/nav-menu/nav-menu.component';
.... More exports ahead
I added the path to this library in my tsconfig.json
"paths": {
"core": [
"dist/core"
],
"core/*": [
"dist/core/*"
],
}
Then it's time to import Modules and components from the library 'core' into the app called 'cms'.
import { WdCoreModule } from 'core';
No errors yet!
Now i'm ready to build my project with: ng serve cms
This will throw the following error:
projects/cms/src/app/app.module.ts(52,30): error TS2307: Cannot find module 'core'.
I've been searching all over for a solution to this problem but i'm kinda stuck. Any coding hero who can help me?
Edit: Extra info for solution
I followed the following post to package and install my build library
https://blog.angularindepth.com/creating-a-library-in-angular-6-part-2-6e2bc1e14121
The following 2 commands did the trick for me:
//package.json
"npm_pack": "cd dist/core && npm pack",
//then
npm install dist/core/core-0.0.1.tgz --save