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:
peerDependency
tsconfig.lib
as paths
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With