How to 'npm link' Angular library with a shared library?
Asked Answered
P

0

8

For my Angular 4.x application (App) I wrote a library (e.g 'Lib') which is currently not AoT compatible.

Both App and Lib depend on a 3rd party library (e.g. 'X'). When I use “npm link” to develop Lib in App, some things stop working since X is now in both App/node_modules and Lib/node_modules, and in runtime there seem to be multiple instances of providers from X. When I delete X from Lib/node_modules everything works fine. I suspect that this is a general limitation of providers and not related specifically to X, but in my case X is actually ngx-translate.

The 'cleanest' workaround I found is to only run ‘npm install’ for App and not for Lib. This way, most dependencies (including X) exist only in App node_modules and the application works fine. However, this causes IDE issues when developing Lib: 1) If I work on Lib’s project, it’s missing the dependencies and doesn’t have intellisense for example (and in addition it doesn't build). 2) If instead I develop Lib from App’s project (directly on node_modules\Lib), it doesn’t have correct version control integration (so I can't check-out for example).

Thanks a lot!

Potemkin answered 10/10, 2017 at 7:28 Comment(1)
If you find how to resolve this issue, can you share please?Koski

© 2022 - 2024 — McMap. All rights reserved.