-->Setting Node and PNPM versions in Cloudflare Workers programmatically --> -->
Try Millefeuille
Setting Node and PNPM versions in Cloudflare Workers programmatically
published: 2026/06/15
category: dev<br>node pnpm cloudflare workers
You can set them by adding the NODE_VERSION and PNPM_VERSION env vars in the Cloudflare Workers dashboard, which is what I did initially, but I wanted to use version ranges and so preferred to set them in code rather than the dashboard.
I’ve wasted a couple of hours so you don’t have to.
Node
//.nvmrc<br>// this uses specifically node v24.16.0<br>24.16.0
// this uses the latest lts version, whether its 22, 24 or 26.<br>lts/*
// THIS DOES NOT WORK!!<br>// it works locally, but not inside cloudflare workers<br>lts/krypton<br>To specify a node version, you must use a .nvmrc file.
PNPM
// package.json<br>"packageManager": "pnpm@11.6.0",<br>"devEngines": {<br>"packageManager": {<br>"name": "pnpm",<br>"version": "11.6.0",<br>"onFail": "download"<br>To specify a pnpm version, you have to add a packageManager field to your package.json. The pnpm site recommends you add devEngines.packageManager for reasons I will not go into. So you end up having to do this.
There are some issues with this.
The packageManager field is enforced by Corepack and as a matter of policy, does not support version ranges. Ref
The packageManager field not supporting ranges is a feature, not a bug.
PNPM however, does support version ranges in devEngines.packageManager, which clashes with Corepack’s policy. So if packageManager is used, devEngines.packageManager must also specify a single version.
There are more, but this is the main issue for me.
wrangler.jsonc
The wrangler docs specify a vars field for environmental variables. It does not work for Node and PNPM.
© Sen Hongo