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?
-
I've been wondering the same thing but I think what we'd need would be a way to change the dependencies in the linked packages to aliases; in other words, if we have a dependency #1 that requires package@2 and dependency #2 that requires package@3 even when we create an alias both dependency #1 and #2 will look for package@<version> and not for the alias. I think the best we could do would be to fork the package, change the dependency to the alias and use the fork instead. This way we should be able to use our aliases. Hope this makes sense!matzar– matzar2022年01月27日 16:03:54 +00:00Commented Jan 27, 2022 at 16:03
1 Answer 1
You can easily do that
set NODE_ENV=development
npm install [email protected] --save
npm install [email protected] --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
1 Comment
npm install and it will be configured to install the packages with the correct dependencies?