Netlify now has support for pnpm out of the box!
Why developers love pnpm
Known for saving disk space and speeding up build times, pnpm is an alternative Node.js package manager that’s especially popular among developers working with monorepos.
With pnpm, you can share dependencies across multiple projects and any changes to those dependencies only require an update to whatever files have changed within the package instead of updating the entire dependency.
Learn more about pnpm in their docs.
How we implemented support for pnpm
To bring pnpm support to Netlify developers, we implemented a solution using Node Corepack.
Corepack is a promising new way to manage package managers. It provides the flexibility to automatically add support for upcoming package managers through new node versions itself without the need to install them independently. This will allow Netlify to more readily add new package managers in the future, should the need arise.
How to use pnpm with Netlify
Using pnpm with Netlify requires only two steps!
First, you’ll need to check in a pnpm-lock.yaml
file by running the following command:
pnpm install
Then, commit your file to git and push up the changes, and Netlify will automatically detect the lock file and run pnpm install
for you during the build.
With pnpm, Netlify takes care of caching the artifacts to make sure your builds are performant.
Old workarounds are no longer needed
Prior to this change, it was possible to use pnpm with Netlify but it required workarounds. Developers found various methods to make pnpm work, some of which required disabling npm.
If you previously used the method that updated the build command to:
[build.environment]
NPM_FLAGS = "--version"
[build]
command = "npx pnpm i --store=node_modules/.pnpm-store && npm run build"
publish = "dist"
Now you can replace this with a single Netlify build command:
[build]
command = "pnpm run build"
Start building with pnpm on Netlify
Support for pnpm has been one of the most highly requested features, and we’re excited to make this available for all developers today! Visit the docs to learn how to get started.
If you have any questions or feedback for us, please send it our way through the forums or open an issue on: https://github.com/netlify/build