I previously wrote a blog post about How to Get Started with the Yarn Package Manager for NodeJS, and noticed that it was appearing in search results for people who were searching for a step-by-step NPM-to-Yarn migration guide.
So without further ado, here’s your guide on how to migrate from NPM to Yarn!
1) Delete NPM’s Lock File
If you’ve ran NPM’s install command in your project, you probably have a file called package-lock.json in the root directory of your project.
Yarn has its own lock file and will print out a warning if it sees NPM’s lock file in the same directory.
Delete the package-lock.json file if it exists.
$ rm package-lock.json
2) Delete node_modules Folder
Next, we need to delete the node_modules folder if it exists. Again, this should be at the root directory of your project.
$ rm -fr node_modules
3) Run Yarn
If you’re reading this, I’m assuming that you already have Yarn installed. If you don’t, head over to Yarn’s website and follow the installation instructions for your operating system.
From the root directory of your project, run the yarn command with no arguments.
Now Yarn will download your dependencies and create a new node_modules folder for your project.
You should now have a new file called yarn.lock in your project directory. If you’re using source control, be sure to check in this file into your source control repository so that you can deterministically install your dependencies across different environments.
Congratulation, that’s i! You’ve now successfully learned how to migrate from NPM to Yarn.
If you’re new to Yarn and are looking to learn the basics of using it to manage your Node.js dependencies, check out my blog post on How to Get Started with the Yarn Package Manager for Node.