'Wrong git branch loaded in node_modules by yarn install command
I have two Typescript projects.
Context: ProjectA depends upon a certain ProjectB branch project
ProjectB git branches:
mainnew_branch
ProjectA package.json
"dependencies": {
"@projectB": "git+https://github.com/projectB.git#new_branch",
}
What I want to achieve?
When I execute yarn install to make sure that the dependencies from the new_branch are loaded in node_modules folder of projectA.
What actually happens?
When I execute yarn install, the dependencies from main branch are loaded.
What I tried?
- I deleted
node_modules&buildfolders and tried to runyarn installagain which did not work. - I deleted
yarn.lockbut the project split another errors that are not related to my changes from thenew_branchat all. - I deleted the
@projectB:git+https://github.com/projectB.git#new_branchdependency from thepackage.jsonfile and I added it viayarn add projectB@git+https://github.com/projectB.git#new_branchwhich did not work.
Solution 1:[1]
The reason is because you should prefix the branch name with either #branch=new_branch or #head=new_branch. Additionally if you wanted to use a particular workspace, you could append that to the URL as well:
https://github.com/projectB#branch=new_branch&workspace=@projectB/workspace-you-want-to-install-from-new_branch
Another way to link things in a more specific way is to do a commit SHA:
https://github.com/projectB#commit=f4f78b319c308600eab015a5d6529add21660dc1&workspace=@projectB/workspace-you-want-to-install-from-that-commit-sha
If at anytime you need to troubleshoot, you should search your yarn.lock to understand what the package.json is being resolved to under resolution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rachel Cantor |
