Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pnpm env use doesn't provide the corepack binary #4029

Open
sodatea opened this issue Nov 22, 2021 · 9 comments
Open

pnpm env use doesn't provide the corepack binary #4029

sodatea opened this issue Nov 22, 2021 · 9 comments

Comments

@sodatea
Copy link
Sponsor Member

sodatea commented Nov 22, 2021

pnpm version:

6.23.0

Code to reproduce the issue:

pnpm env use --global lts
corepack enable

Expected behavior:

Corepack is successfully enabled

Actual behavior:

zsh: command not found: corepack

Actually, corepack can be found at $PNPM_HOME/nodejs/16.13.0/lib/node_modules/corepack but no link is added at $PNPM_HOME, thus the command is not found in $PATH.

Is this intended?

Background:
I'm setting up my new laptop and I'd like to use pnpm to manage my node versions, so I followed the installation guide to install pnpm via shell script. But I need yarn for some of my projects. The current recommended way to install yarn is via corepack. That's when I found out it doesn't work in a pnpm-managed Node.js environment.

Additional information:

  • node -v prints: v16.13.0
  • Windows, macOS, or Linux?: macOS 12.0.1
@zkochan
Copy link
Member

zkochan commented Nov 22, 2021

We could probably link corepack but if corepack will override pnpm, we might have a problem.

@sodatea
Copy link
Sponsor Member Author

sodatea commented Nov 22, 2021

Yeah, I think there's an inherent conflict between corepack and pnpm's philosophy.

But by ensuring $PNPM_HOME always comes before corepack's shims path in the $PATH environment variable, we can work around the conflict temporarily.
And users should use corepack pnpm instead of pnpm in local projects that have the packageManager field.

@sodatea
Copy link
Sponsor Member Author

sodatea commented Nov 22, 2021

To further resolve the conflict, pnpm can add a check for packageManager. Once that field is detected, any pnpm sub-commands except for pnpm env should be delegated to the corepack version of pnpm.

(And maybe the delegation to corepack pnpm can be implemented as opt-in or opt-out. Personally, I don't like the behavior of locking to an exact package manager version. It makes more sense to have an exact version in a lockfile, but not in package.json)

@zkochan zkochan added this to Priority in Status Nov 28, 2021
@zkochan
Copy link
Member

zkochan commented Dec 4, 2021

pnpm can add a check for packageManager

It appears that both Yarn and npm ignore that field. The field is only taken into account when Yarn or npm are managed by Corepack.

@sodatea
Copy link
Sponsor Member Author

sodatea commented Dec 5, 2021

Yeah, but when pnpm env is used, Corepack cannot manage pnpm, pnpm is managing Corepack. So we have to read it.

@sjiep
Copy link

sjiep commented Jul 7, 2022

Does this mean that if I use pnpm as node manager, I can no longer use Corepack? (or Corepack as package manager?)

@zkochan
Copy link
Member

zkochan commented Jul 9, 2022

We did not solve this issue yet. So corepack doesn't work when you install Node.js with pnpm.

@pastelmind
Copy link

We did not solve this issue yet. So corepack doesn't work when you install Node.js with pnpm.

Can we have this in the official docs? Preferably in the "Installation Using Corepack" section.

"Note: pnpm env does not work when you install Pnpm using Corepack. You can install Pnpm directly to use pnpm env, or use another Node.js version manager. See #4029."

@yuri-scarbaci-lenio
Copy link

yuri-scarbaci-lenio commented Apr 12, 2023

Is there a way to switch pnpm version (downgrade) if one installed pnpm with the standalone installation script without completely uninstalling pnpm and installing the downgraded version?

I am afected by #6307 and I need to downgrade from 8 to 7 in my local machine to align with my CI pipeline 🤔

Looks to me that it would eventually become "common enough" to need to support multiple pnpm version in the same machine and a way to quickly switch between them (basically nvm for pnpm?)

I am asking this in this github issue because the sources I have found online so far points out to corepack as the best way to manage diferent pnpm version,
but as per this issue,
corepack is not yet compatible with "standalone pnpm" installation & pnpm env
(and by the looks of it, will probably never be since the philosophy are conflicting and such)

EDIT:
This is what has worked for me to quickly downgrade from pnpm version 8.x to 7.29.3 and have it work as expected ( pnpm add -g pnpm@7.29.3 and pnpm prune are solving some other issues here and there )

  rm -rf $PNPM_HOME
  curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=7.29.3 sh -
  pnpm env use --global 18
  pnpm add -g pnpm@7.29.3
  pnpm prune

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Priority
Status
Priority
Development

No branches or pull requests

5 participants