build
build copied to clipboard
Feature request: Add PNPM support
Which problem is this feature request solving?
pnpm is a robust, mature dependency manager for Node.js projects, and is much faster than npm and yarn. It elegantly solves npm doppelgängers problem and has stricter module resolution, solving yarn ghost modules.
Currently, Netlify users need to use workarounds in order to use pnpm, involving altering a proper project configuration and making it less optimal.
Describe the solution you'd like
Build images should have pnpm@latest preinstalled as a global npm module.
If a pnpm-lock.yaml file is detected in the build.base folder, pnpm install --frozen-lockfile should be run instead of npm install (or even better, the install command should just be exposed as a configuration value so that people can run what they want instead of npm install).
Can you submit a pull request?
~Yes~ ~No~ Maybe.
Hi @jcayzac,
This sounds good.
Most of this would need to be implemented in the build-image (https://github.com/netlify/build-image/issues/447), not @netlify/build though. With the exception of this file which is used only by few optional plugins.
For those who need a quick workaround (like me). This seems to work: https://community.netlify.com/t/using-pnpm-and-pnpm-workspaces/2759
The trick mentioned above --prefix=/dev/null doesn't work in npm7. I prepared a new empty npm project (./empty/package.json) and use that --prefix=/empty
Hi @Jack-Works, can you give more details of your solution? I am having similar issues for using pnpm with netlify, thanks
@hotyes
netlify.toml
[build]
command = "./scripts/netlify.sh"
[build.environment]
NPM_FLAGS="--prefix=./scripts/empty-project/"
scripts/netlify.sh
#!/bin/bash
set -xeuo pipefail
test "$CI" = true || exit 1
npx pnpm install -r --store-dir=node_modules/.pnpm-store
# other build scripts
scripts/empty-project/package.json
{
"description": "This is an empty project used as the destination of netlify npm install."
}
@Jack-Works thanks
Another option to prevent npm to do anything is to pass the --version flag:
[build.environment]
NPM_FLAGS = "--version"
[build]
command = "npx pnpm install --store=node_modules/.pnpm-store && npx pnpm build"
@ehmicky what would you think of adding a NETLIFY_DISABLE_NPM=true or NETLIFY_USE_NPM=false flag? It could be the way to use alternative package managers moving forward, including Yarn (NETLIFY_USE_YARN could even be deprecated in a future Ubuntu version).
For some information, the major Vue and Vite repos have now moved to pnpm.
This is what we have to do to have pnpm work with Netlify.
https://github.com/vuejs/vue-next/blob/master/netlify.toml#L3 https://github.com/vitejs/vite/blob/main/netlify.toml#L3 https://github.com/vuejs/vitepress/blob/main/netlify.toml#L3
Even if we can't have built-in pnpm support right now, I would love to see a more elegant solution to disable the NPM installs similar to @bpierre's proposal (or even make it aware of pnpm-lock.yaml)
Svelte is also all in on pnpm. FWIW. Would love for it to work out of box.
sharing some feedback we received on our docs site on the Monorepos page in support of this feature:
I would love to see pnpm workspaces documentation on this page
Please add pnpm! Netlify is such a great product but not having pnpm by default is a pain. Especially for monorepos which is now trendy.
We got another request on the docs site for PNPM support (also on the Monorepos page):
What is happening with PNPM support? It is rapidly becoming the go to solution for developers with monorepos, even for small solutions that have different front-end and back-end environments.
Just adding a bit more fuel to the fire for supporting PNPM by default! Thank you!
I have found this thread also in hopes of an official support method...
Would really appreciate pnpm support!
https://vercel.com/changelog/projects-using-pnpm-can-now-be-deployed-with-zero-configuration please follow suit
+1
+1
The workaround works fine but it'd be cleaner to have native support for it. +1
related netlify forum thing not that it really changes anything. https://answers.netlify.com/t/using-pnpm-and-pnpm-workspaces/2759
this has been my night today. not fun

+1 Well, Vercel has been supported since March 2022 🥲
When will PNPM support be added? :smirk:
+1
Sorry folks that you waited that long for it but I'm already working on it. Stay tuned :)
Thanks @lukasholzer! 👍 When is the new build image going live?
Hey doing a graduate slow rollout to test if we are not breaking any edge cases worrying a little bit about folks that used a hacky way to install pnpm over the build command.
But it's already in progress to roll it out ;)
Do I have to edit any config for using PNPM? I tried setting the build command to pnpm build, but it didn't work
@hnrq Worked for me. Maybe you're not part of the rollout yet?
@janosh probably. Tried using the same netlify.toml as you but no success :thinking:
Yea I rolled it out to 20% of our starter accounts and going to increase this number now. Nothing special needs to be configured. Just like with npm (If you have a pnpm lock file we will automatically do the pnpm install).
[Edit]: Current rollout progress is on 70% of our starter accounts
If everything is going fine today I will release it to all by the end of the day (CEST)