NPM: Link peer dependency to package alias


Assume I have legacy codebase working with some old packages:

"mobx": "5.15.4",
"mobx-react": "6.1.8",

While developing some new experimental feature, I wanna use newer versions of these packages, but also have to leave legacy in a working state. So, I’m aliasing newer versions of packages so I can use them alongside with the old ones:

"@new/mobx": "npm:mobx@^6.3.13"
"@new/mobx-react": "npm:mobx-react@^7.2.1"

But mobx-react using mobx as a peer dependency. Obviously, the problem is that @new/mobx-react is watching old mobx version and expectedly says that there should be mobx of version 6+.

Is there any way to manually resolve peer dependency of @new/mobx-react, so it will watch @new/mobx and not just mobx? Or, maybe there is a way to implicitly install peer deps for @new/mobx-react in a way it will not override old mobx version?


You can easily do that

set NODE_ENV=development

npm install mobx@5.15.4 --save
npm install mobx-react@6.1.8 --save
npm install @new/mobx@npm:mobx@^6.3.13 --save
npm install @new/mobx-react@npm:mobx-react@^7.2.1 --save

then you must manually install dependencies for your @new/mobx-react like as follows:

cd ./node_modules/@new/mobx-react
npm install --ignore-scripts

that will lead to mobx of version 6.3.14 be in node_modules of your @new/mobx-react

node.js (starting from npm version 3) at first tries to load dependency from internal node_modules of package, then from node_modules of project see : documentation

Answered By – Andrey

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.