In the FrontEnd space, yarn and npm are very commonly know names as the package managers.
Though I have a question for you, what do prefer to use among them?
Package Managers are responsible for the package information and dependency management for any project. If you are familiar with other programming languages, following names are the commonly used package managers there:
- PHP: composer
- Java: Maven and Gradle
- Python: pip
- ASP.NET: NuGet
Node Package Manager (npm)
NPM is the default package manager which comes shipped with Node.js. It has evolved a lot over time along with Node.js and offered many features either with innovation or competition.
Yarn is a package manager built by folks at Facebook to overcome some initial problems of npm. Yarn is the first package manager to introduce lock file for deterministic resolution of packages.
There are so many comparisons of NPM and Yarn on the internet, and they provide enough argument to help in choosing the primary package manager.
I wanted to discuss specifically about the lock files generated by both package managers.
Over the time, my preferences changes for JS Package Mangers as:
- I started preferring Yarn because of Lock file
- Moved back to NPM as Lock file
- Feel like moving back to Yarn as it can offer more on top of basic npm
- Another Package manager?
I stopped using yarn because of the need to have one more package manager, which means you needed to install yarn as a global dependency first on newer setup or CI/CD and then use Yarn.
- Integrity Hashes:
Integrity Hashes in
package-lock.jsonkeep changing based on your Node.js and NPM version. As newer versions of npm use strong SHA algorithm as compared to the older ones; this introduces so many continuous unwanted changes in
- CI/CDs might have Yarn installed by default:
You can use Docker images which already have Yarn installed by default and save time during the installation.
Yarn is a way faster than NPM (I am not making any claims here; I felt that yarn is faster and that's why I am stating that. There are many Install Time comparisons of NPM and Yarn like this one: https://github.com/appleboy/npm-vs-yarn)
- Some Added Features:
Features like Workspaces, Plug-and-Play (PnP) etc. can be leveraged to have better development experience with Yarn.
Both package managers have a lot to offer. Though it is always a dilemma to choose the right one for any project.
This becomes more tough choice when working in a team.
I leave you with some questions:
- What is your preferred package manager?
- Why and how did you reach this conclusion?
If you find this article helpful, please share it with others 🗣
Subscribe to the blog to receive new posts right to your inbox.