2

I have two versions of a package e.g.

@mycompany/mylob v2.0.0

and

@mycompany/mylib v3.0.0

version 3.0.0 has breaking changes from version 2.0.0 but we do not have the capacity to upgrade everything to 3.0.0 as of yet.

Another developer has upgraded an internal package e.g. @mycompany/utils to use version 3.0.0 and that is installed into our codebase so now we are getting compatibility errors when running the build as @mycompany/utils requires version 3.0.0 but the rest of the code in that repository wants version 2.0.0.

Is there a way with yarn/npm that I can install @mycompany/mylib v3.0.0 for @mycompany/utils and have the rest of the code refer to v2.0.0?

Ryan Pays
  • 23
  • 2

3 Answers3

0

You can use custom alias installs:

npm i custom-name:@mycompany/mylib@3.0

You can change custom-name to any valid package name you want to use.

After that you can import the package with this alias name. e.g.:

require("custom-name")/ import * from "custom-name"

Lalaluka
  • 910
  • 1
  • 11
  • 16
0

You can set the dependency explicitly for each of your packages and they'll be handled.

package.json

{
  "name": "project",
  "version": "1.0.0",
  "dependencies": {
    "left-pad": "1.0.0",
    "c": "file:../c-1",
    "d2": "file:../d2-1"
  },
  "resolutions": {
    "d2/left-pad": "1.1.1",
    "c/**/left-pad": "^1.1.2"
  }
}

Your answer lies here for Yarn:

https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/?fbclid=IwAR2aiwN7w5D-YX7kwB4gUITx3VacAuh1qzhJO0q_jGYDm6HjxRe8079GxWA

As for NPM there doesn't seem to be any native solution. You can look at this answer here:

npm equivalent of yarn resolutions?

Aryan3212
  • 121
  • 2
  • 9
-1

For npm install specific version, use npm install [package-name]@[version-number].

  • I think my question is a little hard to understand. I have a parent repo that has both @mycompany/mylib and @mycompany/utils installed. I want the parent repo to use @mycompany/mylib v2 but I want the @mycompany/utils to use @mycompany/mylib v3. – Ryan Pays Aug 18 '22 at 09:21