How To Force Use Yarn Or NPM
In this short post, I’m going to show you how to prevent the usage of npm or yarn, depending on your needs.
This comes in handy when your team or organization has a preference for a specific package manager.
With this method, you ensure that everybody will be using the same package manager.
Let’s get started!
You might not have this file in your codebase. If this is the case, create this file in the root folder of your application.
It allows us to specify package managers configurations and it is used by both npm and yarn.
.npmrc file should have the
engine-strict property marked as
This option tells the package manager to use the version of the engines we have specified in the
package.json file you should add the
engines section if you don’t currently have it.
In the above code, the
package.json file uses a version of
yarn 1.19.1 or greater.
npm we specify a version that doesn’t exist.
This way we make sure that when someone tries to use
npm instead of
yarn, he or she will receive an error that outputs ‘
Running npm install
Once you’ve done the above changes, try to run
You will receive an error that prevents you from using
This, of course, can be done the other way around if you want to prevent the usage of
Related: How to Force Use Yarn or NPM
It is pretty straightforward and easy to ensure that only one package manager must be used inside your project.
This will reduce the chance of errors caused by developers that are using different package managers and it is a good practice to standardize the project’s coding rules and management.
I hope you find this tip useful and let me know what you think about the post through comments below, or on Twitter at @pelu_carol.
If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.