How do I force Yarn to reinstall a package?
Reinstalling a package after just deleting the node module works with:
yarn install --check-files
You can use the yarn link
command. This will set up your local dependency so that whenever you make a change on the dependency, it immediately shows up in your main project without you having to do anything else to update it.
If your main project is in ~/programming/main
and your dependency is in ~/programming/dependency
and is named MyLocalDependency
, you will want to:
1) Run yarn link
(with no additional flags) from within your dependency:
cd ~/programming/dependency
yarn link
2) Run yarn link <name of dependency package>
from within your main project:
cd ~/programming/main
yarn link MyLocalDependency
And you're done!
If you want to switch from a local copy of the dependency to one hosted elsewhere, you can use yarn unlink
.
cd ~/programming/main
yarn unlink MyLocalDependency
cd ~/programming/dependency
yarn unlink
If you're using NPM instead of Yarn, npm link
and npm link <dependency>
work in effectively the same way. To unlink the dependency, run npm rm --global <dependency>
. (This is because npm link
works by creating a simlink in the global NPM set of packages, so uninstalling the linked dependency from the global packages also breaks the link.)
See the npm link
documentation and How do I uninstall a package installed using npm link?
There is one other way.
Just use yarn upgrade package-name
See manual: https://yarnpkg.com/lang/en/docs/cli/upgrade/
As Kevin self-answered, yarn link
is a good option.
But it can cause some issues if the package you are linking has peer dependencies.
What Karl Adler said is also a way to go:
yarn --check-files
But this will reinstall (yarn
without sub-command is the same as yarn install
) every package which has changed.
So, if you really want to just reinstall one package:
yarn add package-name --force
Beside these answers, I have a problem with switching git branches and the yarn
. I have a branch for updating node_modules
packages and another one for my project bug fixing. when I checkout the bug fix and back to updating branch, yarn install
or yarn
returns:
success Already up-to-date.
✨ Done in 0.79s.
But all new packages are not installed. so with the below command, I forced yarn to install all packages:
yarn --check-files
And now it returns:
🔨 Building fresh packages...
✨ Done in 79.91s.