How to also update the package.json version when using yarn update

October 21, 2019

If you run yarn update on a package, yarn will update the package and your yarn.lock file. This is totally fine. As long as you check in your lock file, your developers and team will all have the correct versions of libraries when they run yarn install.

However it will not update the package.json with the new semver for the package. I kind of found this annoying, if only for aesthetic reasons I wanted to quickly see which minimum versions of packages I was using in package.json.

To have yarn also update the semver in your package.json there are a couple of options. Essentially you need to add —latest

Using —latest

If you pass yarn the --latest flag it will update the package.json.

NOTE: this will not respect semver and will update to the latest version. Whatever that might be.

yarn upgrade @graphql-codegen/cli --latest

Using interactive upgrade —latest

If you use the interactive upgrade it will also upgrade the package.json for you

yarn upgrade-interactive --latest

Darragh ORiordan

Hi! I'm Darragh ORiordan.

I live and work in Auckland, New Zealand enjoying the mountains and the ocean.

I build and support happy teams that create high quality software for the web.

Contact me on Twitter!

Get new posts, curated tech articles and coding tips!