9

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?

asked Jan 24, 2022 at 16:25
1
  • 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! Commented Jan 27, 2022 at 16:03

1 Answer 1

2

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

answered Feb 2, 2022 at 10:39
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to do this that is compatible with standard build commands for an npm project? Where I can run npm install and it will be configured to install the packages with the correct dependencies?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.