netlify logo pnpm logo

⚠️ No workarounds are required & you can now use pnpm run build directly

After changing this website to pnpm I noticed netlify don't seem to officially support it.

There are a few issue tickets relating to this & the general idea seems to be to disable npm install then run pnpm install to install dependencies on a prebuild script.

There seem to be a few ways to implement this


I thought the easiest & cleanest way was to add pnpm i to netlify.toml.

[build.environment]
  NODE_VERSION = "14"
  NPM_FLAGS = "--prefix=/dev/null"
[build]
  publish = "public"
  command = "npx pnpm i --store=node_modules/.pnpm-store && npx pnpm run build"

equk/equk-gatsby@c713c72

Important

You will probably want to tell netlify to clear the cache before building if switching from npm or yarn.


Update 2022 #

Forcing npm to use /dev/null using prefix results in non-zero exit code.

npm ERR! code EEXIST
npm ERR! syscall mkdir
npm ERR! path /dev/null
npm ERR! errno -17
...
Build was terminated: Build script returned non-zero exit code: 1

A fix is to force npm to show version info with --version.
This stops other npm operations & just gives cli feedback on version installed.

See the updated netlify.toml below.

[build.environment]
  NODE_VERSION = "16"
  NPM_FLAGS = "--version"
[build]
  publish = "public"
  command = "npx pnpm i --store=node_modules/.pnpm-store && npx pnpm run build"

If you check the build log after these changes you should now see

8.15.0
NPM modules installed

Update Oct 2022 #

Netlify now supports pnpm using corepack.

Update netlify.toml with pnpm run build

 [build.environment]
   NODE_VERSION = "16"
-  NPM_FLAGS = "--version"
 [build]
-  publish = "public"
-  command = "npx pnpm i --store=node_modules/.pnpm-store && npx pnpm run build"
+  command = "pnpm run build"

The source for the site is available on github.

equk-gatsby