volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
10.32k stars 220 forks source link

Support for pnpm #737

Open willsoto opened 4 years ago

willsoto commented 4 years ago

Seems to be a fairly popular alternative to npm and yarn. Apologies if this has already been suggested but I couldn't find an existing issue. It would be great to be able to volta pin pnpm.

https://pnpm.js.org/en/

BleedingDev commented 1 year ago

Great, thanks! I am already trying it.

I would also add to limitations that it is not possible to pin pnpm. :)

chawyehsu commented 1 year ago

@pegak pnpm pinning is supported in 1.1.1. Perhaps you are encountering some issues with it. Please feel free to open a new issue to let us know.

BleedingDev commented 1 year ago

Oh, didn't have the update, sorry. Trying now!

j commented 1 year ago

@chawyehsu

~/Code/example main* ❯ volta --version
1.1.1

~/Code/example main* ❯ pnpm --version
7.27.1

~/Code/example main* ❯ volta pin pnpm@7.27.1
error: Only node and yarn can be pinned in a project

Use `npm install` or `yarn add` to select a version of pnpm for this project.
j commented 1 year ago

Also, pnpm run commands use global node:

 WARN  Unsupported engine: wanted: {"node":">=19.0.0"} (current: {"node":"v18.13.0","pnpm":"7.27.1"})
chawyehsu commented 1 year ago

@j and for future comments here, you CANNOT pin pnpm if you do not enable the native pnpm feature for Volta while it's experimental. Follow the doc and enable native pnpm support, and notice the limitations including the migration note.

$ volta --version
1.1.1

# VOLTA_FEATURE_PNPM=0
#
# You are using the packaged pnpm which will fail to pin
$ volta pin pnpm@7.27.1
error: Only node and yarn can be pinned in a project

Use `npm install` or `yarn add` to select a version of pnpm for this project.

# VOLTA_FEATURE_PNPM=1
#
# Enable the _native_ pnpm feature in order to pin
$ volta pin node pnpm@7.27.1
success: pinned node@18.14.2 (with npm@9.5.0) in package.json
success: pinned pnpm@7.27.1 in package.json
j commented 1 year ago

I just came across that doc. Sort of a pain as things seem so disconnected when using pnpm. pnpm is great and recommended by turborepo, but pnpm commands use global node, etc, etc. Fun!

chawyehsu commented 1 year ago

Sorry for the inconvenience @j

Also, pnpm run commands use global node:

 WARN  Unsupported engine: wanted: {"node":">=19.0.0"} (current: {"node":"v18.13.0","pnpm":"7.27.1"})

but pnpm commands use global node, etc, etc

This warning is from pnpm and not relevant to the current implementation of pnpm support for Volta. In the implementation, we only intercept a basic set of pnpm commands to work with Volta in pinning, etc. And most of the workflows are directly passed to pnpm transparently. Hence there may be things unlinked when using pnpm at present because pnpm may work outside of Volta's control.

Talking about the warning message, that's because you specified the node version via engines in package.json for your project. Something like this:

{
  "engines": {
    "node": ">=19"
  }
}

And pnpm will print out the warning message when you are not using the corresponding version of node.^1 It's not about the global node being used, it's about that you haven't pinned the node via Volta for your project.

IIRC, Volta does not support reading the engines property and pinning node as per its specified version yet. There have been tracking issues about supporting engines^2. And as one of the users of Volta, I wish it will be eventually supported, too.

For now, to avoid pnpm's warning message, you can pin a node version that is identical to the one of engines by volta pin node@19.x.x, or delete the engines property.

+  "volta": {
+    "node": "18.13.0",
+    "pnpm": "7.27.1"
+  },
- "engines": {
-   "node": ">=19"
-  }

Anyways, doing some searches on the issue trackers will help.

michaelhays commented 1 year ago

Is there somewhere we're tracking work/requirements on the known limitations of pnpm support?

I'd love to help on those -- from my understanding, we just have the global installations and automatic migrations from the Volta pnpm global left until this can go from experimental to stable.

(FWIW, I've been using pnpm with VOLTA_FEATURE_PNPM set (see #1394) for a couple of months now and it's been working perfectly)

lolmaus commented 1 year ago

I was running into this error:

❯ volta install pnpm
error: Executable 'pnpm' is already installed by corepack

I resolved it by using this command instead:

corepack prepare pnpm@latest --activate
dwiyatci commented 6 months ago

@chawyehsu Seems like I got into this awkward state in a project where:

"volta": {
  "node": "18.18.2"
},

But then when I ran: pnpm, it threw: "Volta error: No pnpm version found in this project.".

I've got volta v1.1.1 and export VOLTA_FEATURE_PNPM=0 set in my .zshrc.

I've read this bit from https://docs.volta.sh/advanced/pnpm#migrating, but I don't quite get it:

Once you switch to the native pnpm support, you may not remove the isolated old pnpm package by calling the same command because lack of uninstall implementation as of now.

Running which pnpm outside of the project results in /Users/Glenn/Library/pnpm/pnpm. But running which pnpm from the project results in /Users/Glenn/.volta/bin/pnpm.

My intention is to keep using globally-installed pnpm without volta gets in the way. How can I achieve that back? Thank you 🙏

chawyehsu commented 6 months ago

keep using globally-installed pnpm without volta gets in the way.

@dwiyatci There is nothing VOLTA_FEATURE_PNPM can do, Volta can't deal with pnpm that's not installed with Volta. You want to use pnpm outside of Volta then you may need to remove Volta's pnpm shims from PATH.

dwiyatci commented 6 months ago

you may need to remove Volta's pnpm shims from PATH.

Thanks for the pointer, @chawyehsu! I did the following and seems like I managed to switch back using global pnpm properly:

Have a nice weekend! :)🎉

ghost commented 2 months ago

It's almost four years since this issue was raised, but why is it still supported as an experiment and not made official?

Please let us know if there are any unresolved issues. Volta won't support pnpm forever, so I'm starting to avoid it.

ShravanSunder commented 1 month ago

i'm also curious about the experimental tag and what's outstanding

chawyehsu commented 1 month ago

The project is fully community driven now. It's ok that you going to avoid this avoid that, your business is your business. However that does not help at all just complaining and pressuring in this thread. Read the source code, know how it work and what is unresolved, and submit PRs to contribute, that is the way! And that's how I did and added the existing pnpm support.

smblee commented 1 month ago

FYI I use https://mise.jdx.dev/ now instead of volta.

BleedingDev commented 1 month ago

And now I switched to Proto. :) Would be good to see some comparison.

https://moonrepo.dev/proto