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
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
- JavaScript: npm and yarn
- Java: Maven and Gradle
- Python: pip
- ASP.NET: NuGet
- etc.
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
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
yarn.lock
- Moved back to NPM as Lock file
package-lock.json
was introduced - Feel like moving back to Yarn as it can offer more on top of basic npm
My Reasons:
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.json
keep 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 package-lock.json
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.
Speed
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.
Conclusion
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 like:
- What is your preferred package manager?
- Why and how did you reach this conclusion?
Let me know through comments ๐ฌ or on Twitter at ย @patel_pankaj_ ย and/or ย @time2hack
If you find this article helpful, please share it with others ๐ฃ
Subscribe to the blog to receive new posts right to your inbox.
Credits
Originally published at https://time2hack.com on May 27, 2020.
Top comments (0)