corepack
corepack copied to clipboard
pnpm stuck on 7.1.7 under corepack
Copying pnpm issue here: https://github.com/pnpm/pnpm/issues/5875
pnpm version: 7.1.7
Code to reproduce the issue:
corepack prepare [email protected] --activate; pnpm -v
Expected behavior:
It should output I'm on 7.22.0
Actual behavior:
Preparing [email protected] for immediate activation...
7.1.7
Additional information:
node -vprints: v16.17.1- Windows, macOS, or Linux?: macOS, nvm
which pnpm
~/.nvm/versions/node/v16.17.1/bin/pnpm
Have you run corepack enable? Your reproduction is missing it;
$ docker run --rm node:16.17.1 bash -c "corepack prepare [email protected] --activate; pnpm -v"
Preparing [email protected] for immediate activation...
bash: pnpm: command not found
vs
$ docker run --rm node:16.17.1 bash -c "corepack enable; corepack prepare [email protected] --activate; pnpm -v"
Preparing [email protected] for immediate activation...
7.22.0
Yes, I've done corepack enable the first time I installed it, otherwise I wouldn't have been able to use pnpm.
But now, I've run it again, just for testing and after that I'm able to do the upgrade.
So the bug report is basically this: To update pnpm, I need to repeatedly run corepack enable, before each update.
Something happened that caused the binary to be overwritten. It's not possible to say what for certain with the info you have, but Corepack doesn't remove them by itself, so it points to a third-party issue.
Some Node.js version managers in particular are known to forget the Corepack status when switching between Node versions. Given you use nvm, it's likely what happened here.
Also try echo $PATH or echo %PATH% which will show you the precedence of which directories are searched on your machine. As mentioned above, likely nvm path is prepended in front of the corepack path which is causing it to prefer nvm.
The path is good, it's the same as it was when the bug was present.
which pnpm
~/.nvm/versions/node/v16.17.1/bin/pnpm
I definitely haven't done anything with global packages. What I have done though is I removed some of my cache folders after migrating to pnpm. What does corepack enable do exactly? Could I have broken it by deleting my cache folders?
What does
corepack enabledo exactly?
It adds the binaries to your path, next to the node one:
https://github.com/nodejs/corepack/blob/5633a158986bae193a737b82b08d0139e078694b/README.md#L128-L138
If you're using nvm, I'm not sure how this works as I believe it exposes different node binary depending on the context.
Could I have broken it by deleting my cache folders?
What cache folders?
Just the npm, yarn, etc. cache folders I found under home dir and Library.
I would like to add that the corepack looks for the packageManager property in package.json, Just make sure to update that as well to the latest version.
I was facing the same issue and it turns our my problem was due to the package.json configuration. I ran this command
$ corepack prepare [email protected] --activate
Preparing [email protected] for immediate activation...
Despite the command and its output, corepack actually installs [email protected] because that's what's specified in package.json.
This is very confusing behavior. I would consider it more intuitive for corepack to always install an explicitly-given version, and maybe output a warning if the version in package.json does not match.
I think https://github.com/nodejs/corepack/pull/291 has addressed this, you can now use corepack use … and corepack up (and skip the corepack prepare command). Closing, let me know if I missed something.