Over the past couple of months, I have been having some issues with npm. Between the upgrading of npm Windows begin a pain and a version incompatibility with node I have just gotten frustrated with it. This post is going to cover the steps to use Yarn as a replacement for npm in an ASP.NET Core application.
The first step is to get Yarn installed. Head over to this site and download and run the installer for your operating system.
Open a command prompt in the same directory as your project’s package.json file and run the following command.
This will create a yarn.lock and lay out the node_modules folder using Yarn’s resolution algorithm.
I did hit the following error when I did the yarn command. I left out the specific file that it had an issue with because I am sure yours would be different.
Error: EPERM: operation not permitted, copyfile...
To clear the issue I just deleted the node_modules directory and let Yarn recreate it. It might also work to use a command prompt with administrator privileges.
With the Yarn extension installed there are a couple of settings that are helpful to change. All the setting we will be changing can be found under the Tools > Options menu. The first is to have yarn install run when the package.json is saved. Look under Web > Yarn Installer for this option.
The second setting is to turn off automatic NPM restore so packages are restored twice. This requires the options under NPM to be set to false. The options can be found in Projects and Solutions > Web Package Management > Package Restore.
The extension helps with Yarn integration, but the integration still isn’t as full-featured as using NPM. At my current level of frustration having to manually restore package when I open a project on a new PC is totally worth it.
So far Yarn has been great and I have not hit any issues, but my usage has also been limited. It seems like a solid alternative to NPM.
Also published on Medium.