Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 multiple library cross-dependency

I have installed multiple libraries in angular 6 and I need to import one library in another. They depend on each other but it's not working

Here's how it goes:

ng generate library lib1

ng generate library lib2

Now in the main application, in package.json I add to tsconfig.json in compilerOptions the libraries (they are automatically inserted)

"paths": { "lib1": ["../distPack/lib1"], "lib2": ["../distPack/lib2"] }

(I modified the path where they are generated to be distPack)

I can import them in app.module and everything works fine

import { Lib1Module } from 'lib1'

PROBLEM

I want to: import { Lib1Module } from 'lib1' in lib2/src/lib/lib2.module.ts

And and it can't find it.

What I tried:

  1. peerDependency
  2. adding it to tsconfig.lib as paths
  3. including it as direct path (fails in --prod build)

Update

If I build the set the paths in main tsconfig.json to

"paths": { "lib1": [ "dist/lib1" ],

the other libraries can import it without a problem BUT it can no longer be imported in app.module

like image 952
Pian0_M4n Avatar asked Jul 08 '18 16:07

Pian0_M4n


1 Answers

I want to: import { Lib1Module } from 'lib1' in lib2/src/lib/lib2.module.ts

And and it can't find it.

Based on this, when you import a library inside your module it'll search for it in same directory inside node_modules.

So if you want to include libr1 inside lib2 you should go to lib2 directory and install lib1 inside that one.

I hope this help you, If it isn't your answer tell me more about your problem

like image 167
molikh Avatar answered Nov 07 '22 20:11

molikh