-
Notifications
You must be signed in to change notification settings - Fork 473
Description
@bobzhang asked me to create an issue here for a discussion in the ReasonML #general Discord.
The way that npm installs dependencies often causes problems with BS/Reason compiler when two packages want to install the same dependency but at different, possibly incompatible versions.
For example, if you have a core library mycore, and two packages:
mypackage1- depends onmycorev1.0mypackage2- depends onmycorev2.0
And an app myapp which depends on mypackage1 and mypackage2. When you run npm install for myapp it might install mycore v1.0 somewhere in node_modules, and mycore v2.0 somewhere else (either at the root, or nested).
When you try to run the BS/reason build, it seems to just choose one version or the other, and you get warnings like this:
Duplicated package: mycore /home/awhite/dev/andywhite37/myapp/node_modules/mycore (chosen) vs /home/awhite/dev/andywhite37/myapp/node_modules/mypackage2/node_modules/mycore in /home/awhite/dev/andywhite37/myapp/node_modules/mypackage2
Other languages solve this type of problem using:
- dependency version ranges and constraint solvers to decide on a single version to install
- package sets - only one version of each library is allowed in a package set
- exact versions with single dependency installs
The key is that you only have one version of each library installed. I would not rely on semantic versioning to aid with this, as that is basically just an honor code. Also, pure JS libraries probably need to allow duplicate nested installs - it's more the BS/reason code that needs more control over library installs.