build icon indicating copy to clipboard operation
build copied to clipboard

Feature request: Add PNPM support

Open jcayzac opened this issue 5 years ago • 21 comments

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.

jcayzac avatar Jul 08 '20 01:07 jcayzac

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.

ehmicky avatar Jul 13 '20 16:07 ehmicky

For those who need a quick workaround (like me). This seems to work: https://community.netlify.com/t/using-pnpm-and-pnpm-workspaces/2759

poteirard avatar Oct 20 '20 13:10 poteirard

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

Jack-Works avatar Jun 11 '21 03:06 Jack-Works

Hi @Jack-Works, can you give more details of your solution? I am having similar issues for using pnpm with netlify, thanks

hotyes avatar Jul 02 '21 09:07 hotyes

@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 avatar Jul 04 '21 07:07 Jack-Works

@Jack-Works thanks

hotyes avatar Jul 06 '21 06:07 hotyes

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).

bpierre avatar Aug 27 '21 14:08 bpierre

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)

antfu avatar Oct 13 '21 06:10 antfu

Svelte is also all in on pnpm. FWIW. Would love for it to work out of box.

arxpoetica avatar Jan 10 '22 21:01 arxpoetica

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

rstavchansky avatar Feb 23 '22 17:02 rstavchansky

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.

ZetiMente avatar Feb 28 '22 16:02 ZetiMente

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.

KyleBlankRollins avatar Mar 08 '22 17:03 KyleBlankRollins

Just adding a bit more fuel to the fire for supporting PNPM by default! Thank you!

ehowey avatar Mar 12 '22 05:03 ehowey

I have found this thread also in hopes of an official support method...

kevinkhill avatar Apr 10 '22 02:04 kevinkhill

Would really appreciate pnpm support!

rohanrajpal avatar May 15 '22 09:05 rohanrajpal

https://vercel.com/changelog/projects-using-pnpm-can-now-be-deployed-with-zero-configuration please follow suit

einSelbst avatar Jun 13 '22 21:06 einSelbst

+1

ghostdevv avatar Jun 13 '22 21:06 ghostdevv

+1

davidboom95 avatar Jun 23 '22 00:06 davidboom95

The workaround works fine but it'd be cleaner to have native support for it. +1

wiredmatt avatar Aug 08 '22 23:08 wiredmatt

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 image

swyxio avatar Aug 28 '22 06:08 swyxio

+1 Well, Vercel has been supported since March 2022 🥲

Planxnx avatar Sep 13 '22 21:09 Planxnx

When will PNPM support be added? :smirk:

martio avatar Sep 27 '22 18:09 martio

+1

hnrq avatar Oct 11 '22 05:10 hnrq

Sorry folks that you waited that long for it but I'm already working on it. Stay tuned :)

lukasholzer avatar Oct 11 '22 08:10 lukasholzer

Thanks @lukasholzer! 👍 When is the new build image going live?

janosh avatar Oct 17 '22 15:10 janosh

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 ;)

lukasholzer avatar Oct 17 '22 15:10 lukasholzer

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 avatar Oct 17 '22 21:10 hnrq

@hnrq Worked for me. Maybe you're not part of the rollout yet?

janosh avatar Oct 17 '22 21:10 janosh

@janosh probably. Tried using the same netlify.toml as you but no success :thinking:

hnrq avatar Oct 17 '22 22:10 hnrq

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)

lukasholzer avatar Oct 18 '22 08:10 lukasholzer