pnpm with Workers Builds

What's the best way to use pnpm with Workers Builds? Build output suggests it's detected but not installed.
09:12:56.850 Initializing build environment...
09:13:07.058 Success: Finished initializing build environment
09:13:07.184 Cloning repository...
09:13:09.031 Detected the following tools from environment: [email protected], [email protected]
09:13:09.034 Restoring from dependencies cache
09:13:09.036 Restoring from build output cache
09:13:09.290 Installing project dependencies: pnpm install --frozen-lockfile
09:13:09.527 No preset version installed for command pnpm
09:12:56.850 Initializing build environment...
09:13:07.058 Success: Finished initializing build environment
09:13:07.184 Cloning repository...
09:13:09.031 Detected the following tools from environment: [email protected], [email protected]
09:13:09.034 Restoring from dependencies cache
09:13:09.036 Restoring from build output cache
09:13:09.290 Installing project dependencies: pnpm install --frozen-lockfile
09:13:09.527 No preset version installed for command pnpm
7 Replies
Jürgen Leschner
maybe try to clear the build cache or delete/regenerate the lockfile? Looks like a version mismatch from the log above
Kris
KrisOP3w ago
It seems I need to make .tools-versions match the installed versions, or override the installed versions to match .tools-versions. Too bad Workers Builds doesn't just pick up the versions in .tools-versions when setting up the environment.
Jürgen Leschner
@Kris it appears that you can set the desired pnpm version in the workers build config (like for cloudflare pages described here)
Jürgen Leschner
Note PNPM v8.x
No description
Jürgen Leschner
Setting the PNPM_VERSION for the build, also appears to force the use of pnpm over npm, even if there is no lockfile (TIL 🎉) And if you set the version to 9, it will pull the latest (v9.15.2) even if the build environment already has say v9.10 installed.
Kris
KrisOP3w ago
Thanks, yes, I've set PNPM_VERSION so an update doesn't break the build. I just wish it got the value from .tool-versions so I don't need to remember to update the build config when we change the version.

Did you find this page helpful?