Skip to content
Index

[Node.js] Lock down pnpm version in package.json

package.json
"engines": {
"pnpm": "10"
}

Use pnpm to manage pnpm versions

As of pnpm v10, it can manage which version of itself to use, based on the packageManager field in package.json.

First, install pnpm globally:

Terminal window
npm install -g pnpm

Then, set the packageManager field in your project’s package.json to the version of pnpm you want to use for your project. Example:

package.json
"packageManager": "pnpm@10.4.1"

Now, regardless of the global version of pnpm you have installed (as long as it’s v10+), when you run pnpm commands in your project, it will use the version specified in package.json.

Use corepack to manage pnpm versions

You can use corepack to manage the correct version of pnpm for you, if you’d like.

First enable it (once) with:

Terminal window
corepack enable

Then run:

Terminal window
corepack use pnpm@latest

This will download and install the latest version of pnpm and set that exact version in the packageManager field of your package.json.

Now, when you run pnpm commands, corepack will ensure the correct version is used.