The npm community forum has been discontinued.
To discuss usage of npm, visit the GitHub Support Community.
Howto to expose dependent package to library consumer
I have started building a npm package called “jpf”. This package has a dependency on another npm package “knockout”.
The jpf package exposes public properties that come from the knockout library.
Some way I have to make sure that both the application consuming the “jpf” library and the library itself use the same instance of the “knockout” library because the code has checks on “instanceof” that fail if separate instances of the knockout library are used
After some trail and error I have found two ways to achieve this goal.
- Expose the whole “knockout” library as a property on my “jpf” library. So the consuming application has access to the knockout library by importing jpf and then accessing knockout by doing jpf.ko…….
- Add “knockout” as a peer dependency to the “jpf” library and force the consuming application to have a dependency on “knockout”. And further make sure that knockout is not added to my bundle but is first resolved in the jpf consuming application.
Question : Is one of the solutions described above the correct way of doing this or are there even more and better options. What is the best way to ensure only one instance of an dependent library exists.