There’s probably multiple articles of this sort online. But I’m going to be doing these same steps for a few of my projects so I figured I might as well make a post about it 🦀
This guide covers how to switch from Yarn to npm to manage dependencies for a project. This guide assumes a non-complex setup (eg: no monorepos). This guide will not cover migrating away from specific features such as Yarn workspaces.
To switch from Yarn to npm run the following steps in your project’s folder:
- Remove
yarn.lockas this file will no longer be used. - Run
npm install. This will generate apackage-lock.jsonfile. - Use
git grep yarnto find any remaining references toyarn. Replace these references either with an equivalent from npm cli or other command as appropriate. - Try running and building your application to confirm that it still works.
Here’s some other things that you may need to check:
- Yarn’s resolutions can be replaced with npm’s overrides provided that you are using npm v8.3.0 or newer.
- I have not verified this yet, but
.yarnrcor.yarnrc.yamlfiles could potentially be replaced with an .npmrc file. Available config options can be found in config | npm Docs.