Skip to content

Duplicated package installation/handling #3660

@andywhite37

Description

@andywhite37

@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 on mycore v1.0
  • mypackage2 - depends on mycore v2.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:

  1. dependency version ranges and constraint solvers to decide on a single version to install
  2. package sets - only one version of each library is allowed in a package set
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions