Cloudflare Pages Node/Yarn versions

I spent an hour today debugging this error which occurs when deploying a Github repo to Cloudflare Pages:

07:50:42.633    Success: Finished cloning repository files
07:50:43.436    Detected the following tools from environment: yarn@3.6.3, nodejs@18.17.1
07:50:43.438    Installing project dependencies: yarn
07:50:44.208    ➀ YN0070: Migrating from Yarn 1; automatically enabling the compatibility node-modules linker πŸ‘
07:50:44.211    
07:50:44.264    ➀ YN0000: β”Œ Resolution step
07:50:48.645    ➀ YN0032: β”‚ fsevents@npm:2.3.3: Implicit dependencies on node-gyp are discouraged
07:50:52.853    ➀ YN0000: β”” Completed in 8s 590ms
07:50:52.879    ➀ YN0000: β”Œ Post-resolution validation
07:50:52.879    ➀ YN0028: β”‚ The lockfile would have been modified by this install, which is explicitly forbidden.
07:50:52.880    ➀ YN0000: β”” Completed
07:50:52.880    ➀ YN0000: Failed with errors in 8s 618ms

It turns out that Cloudflare Pages has two versions of Ubuntu (20 and 22) and each version comes bundled with specific versions of Node and Yarn. I was using Yarn v1 on my local machine and Cloudflare Pages was using Ubuntu 22 which in turn uses Yarn v3.

I was stumped by the error because Cloudflare Pages works for other projects that I use Yarn v1 for locally. It turns out that you can pick your version of Ubuntu under Settings > Build & Deployments > Build System Version.

Screenshot 2023-09-28 at 10.22.49β€―AM.png

The way Cloudflare picks the Ubuntu version for you project appears based on the node version required in package.json and for Vite this is:

  "engines": {
    "node": "^14.18.0 || >=16.0.0"
  },

Ubuntu 20 uses Node version 12.x, so I believe Cloudflare chose Ubuntu 22 due to my project requiring Node 14.x/16.x.

Locally I use Node 16.14 and Yarn 1.22. Because Node and Yarn versions are tied together on Cloudflare pages, you need to configure your local environment to reflect either the Ubuntu 20 or Ubuntu 22 configuration: Either use Node 12.x + Yarn 1.x OR Node >=14.x/16.x + Yarn 3.x

 
12
Kudos
 
12
Kudos

Now read this

Forbidden Peak

Late summer/early fall is my favorite season in the Cascades. The mornings are crisp but the evenings are fairly warm. You can get away with a light backpack because you don’t need to bring warm layers or serious snow gear. Eldorado,... Continue →