DEV Community

Cover image for ERR_PNPM_BAD_PM_VERSION This project is configured to use vX of pnpm. Your current pnpm is vY
Michal Bryxí
Michal Bryxí

Posted on

ERR_PNPM_BAD_PM_VERSION This project is configured to use vX of pnpm. Your current pnpm is vY

The problem

If you started using corepack to manage versions of your package manager you might have bumped into a very curious case of two very similar commands returning different results:

# Calling `pnpm` directly, this works perfectly fine:
> pnpm install
Lockfile is up to date, resolution step is skipped
Already up to date
Done in 1.5s

# Calling `pnpm` through `ember-cli`, this one fails:
> ember install ember-leaflet
🚧  Installing packages... This might take a couple of minutes.
Command failed with exit code 1: pnpm add --save-dev ember-leaflet
 ERR_PNPM_BAD_PM_VERSION  
This project is configured to use v9.7.0 of pnpm.
Your current pnpm is v9.1.2
Enter fullscreen mode Exit fullscreen mode

You might have tried (like me) to "fix the project" by running:

> corepack prepare pnpm@9.7.0 --activate
> corepack use pnpm@9.7.0
> corepack install --global pnpm@9.7.0
Enter fullscreen mode Exit fullscreen mode

But the result would be still the same.

The analysis

What is the issue here? Why do we have enforced v9.7.0 everywhere, but ember command uses v9.1.2 somehow?

If you run version check from within your project you will, indeed, get the correct version:

> cd ~/my-project
> pnpm --version
9.7.0
Enter fullscreen mode Exit fullscreen mode

But if you run the same command from somewhere else (your home) directory, you will get the "wrong" version:

> cd ~
> pnpm --version
9.1.2
Enter fullscreen mode Exit fullscreen mode

Which is a clue. Now let's take a look at where did the ember in your ember install ember-leaflet command came from:

> cd ~/my-project
> which ember
/Users/michal/Library/pnpm/ember
Enter fullscreen mode Exit fullscreen mode

Aha! So it's my global ember-cli installation and not the project one (which lives in ~/my-project/node_modules/ember-cli/bin/ember).

Solution

Local

If you want to use in project installed version of ember-cli, you can do so by executing the ember command via pnpm exec:

> pnpm exec ember install ember-leaflet
Enter fullscreen mode Exit fullscreen mode

Global

Or you can pin the global version of pnpm to the version matching your project:

> corepack install --global pnpm@9.7.0
> pnpm --version
9.7.0
> cd ~/my-project
> ember install ember-leaflet
🚧  Installing packages... This might take a couple of minutes.
pnpm: Installed leaflet@^1.9.3
Installed addon package.
Enter fullscreen mode Exit fullscreen mode

pnpm managed by corepack

If you want to solve the global version mismatch, you might bump into an issue where pnpm was installed from different sources than corepack and changing the version within corepack would not influence what version is executed as the other installation would take precedence.

I don't have a straightforward solution for this as it heavily depends on your situation and what setup you want to run, but if you (like me) want to just keep using corepack for managing your pnpm versions you might try following:

  1. brew uninstall pnpm
  2. npm uninstall pnpm -g
  3. Follow the uninstalling pnpm docs
  4. Remove any references of PNPM_HOME from your shell config (~/.zshrc)
  5. Reload your shell config (~/.zshrc)
  6. corepack install --global pnpm@9.7.0
  7. Check what version is now globally available by running in your home directory: pnpm --version

Home directory shenanigans

It might happen that when you're in your home directory pnpm --version command still shows some other version than your global one. Why is that? Well corepack uses packageManager field in your package.json to determine if it should use local version instead of the global one. And it might be that your home directory contains package.json file and thus it looks like a project folder. Simply remove this file, you very likely created it by accident and don't want package.json in ~ directory.


Illustration made by ChatGPT v4o using prompt: "Confused hamster looking at spaghetti of source code, trying to make sense of it --ar 16:9"

Top comments (0)