How to specify node and npm version for the current project, using .npmrc and .nvmrc

Fredric Cliver
2 min readFeb 26, 2023
Photo by Gabriel Heinzer on Unsplash

You need two files to specify and restrict to use of the proper version of npm and node.

.npmrc

engine-strict=true

package.json

"engines": {
"node": ">= 8.9.4 < 15.0",
"npm": ">= 5.6.0"
}

.nvmrc

14.21.3

With these settings, you cannot just install packages by your local version of npm and node.

You’re going to face this message on the terminal

 pnpm install                     
ERR_PNPM_UNSUPPORTED_ENGINE Unsupported environment (bad pnpm and/or Node.js version)

Your Node version is incompatible with "/Users/[My name]/Projects/[My organisation]/[My project]".

Expected version: >= 8.9.4 < 15.0
Got: v19.7.0

This is happening because the package's manifest has an engines.node field specified.
To fix this issue, install the required Node version.

The first thing you need to use is this

nvm use

This command just finds the version of this project after looking for the new setting files you added above.

Found '~~~~' with version <14.21.3>
N/A: version "14.21.3 -> N/A" is not yet installed.

You need to run "nvm install 14.21.3" to install it before using it.
nvm install 14.21.3
Downloading and installing node v14.21.3...
Downloading https://nodejs.org/dist/v14.21.3/node-v14.21.3-darwin-x64.tar.xz...
#################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.21.3 (npm v)

--

--

Fredric Cliver

Majored in Physics, self-taught and worked in the IT industry as a Dev/Design/Planning for 11 years. And I had run my Startup for 3 years. I fancy a ☔️ 🇬🇧