How do I eliminate a "duplicate package" error?


#1

I am writing a program that needs to use bs-xmlhttprequest and also needs bs-webapi. It turns out that bs-xmlhttprequest already has bs-webapi as a dependency.

In my main program, if I install only bs-xmlhttprequest, then this fails with The module or file Webapi can't be found.:

module D = Webapi.Dom;

If I install both libraries and list them both in my bsconfig.json, then the compile succeeds, but I get a warning:

Duplicated package: bs-webapi /home/david/client/node_modules/bs-webapi (chosen) vs /home/david/client/node_modules/bs-xmlhttprequest/node_modules/bs-webapi

How do I get what I want (a compile without errors or warnings)?


#2

This is probably happening because the version of bs-webapi that you’re requesting directly is incompatible with the version listed in bs-xmlhttprequest's package.json. It’s just a warning because (short of some very stateful libraries like React, or major api changes) this kind of “just works” when compiling to JS. The downside is you will ship two versions of this code and things could break if the two versions have breaking changes between them.

If that’s the issue you can fix by making sure that your package manager is able to resolve to a single version of bs-webapi for your code and your dependencies.