← Back to blog

Using PNPM on Netlify

When I first switched my website over to PNPM instead of Yarn, I noticed that my Netlify build were failing, although I set the build command to pnpm build. Here’s a solution for everyone having the same issue, since I couldn’t find any relevant information out there.

Switching to PNPM

Switching to PNPM locally is almost instant. it’s as easy as removing the older package-lock.json or yarn.lock file and then installing PNPM. (you can install it using a number of different ways, more information here)

(Invoke-WebRequest 'https://get.pnpm.io/v6.14.js' -UseBasicParsing).Content | node - add --global pnpm

PNPM uses a very familiar syntax, so I won’t explain further. You just have to track the package.json and newly generated pnpm-lock.yaml file to install dependencies on Netlify

Telling Netlify to build using PNPM

Netlify offers a few different ways to interact with the build-environment. The easiest (and the one I use), is using the Netlify UI on their website. I will explain further how to use PNPM via the UI, but if you use a netlify.toml file, the approach should be roughly the same.

Actually, the approach is easy. Netlify doesn’t have PNPM installed on their buildenvironment, but they do have NPM & Yarn installed. So we can mis-use them to install PNPM and go on from there. Just add the following as a buildcommand:

pnpm build || ( npm install pnpm && pnpm build )

The script will try to run pnpm build at first. If it fails, because PNPM is not installed, it will install PNPM using NPM and then proceed to run pnpm build.

Clever right.

Written by Elian Van Cutsem

← Back to blog
  • Elians Astro Startkit

    Elians Astro Startkit

    I just published the setup I use for my personal projects. You can read more about it in this blogpost.

  • So, I'm leaving vBridge

    So, I'm leaving vBridge

    After spending a couple of years at vBridge Cloud, I'm leaving the company. I've worked at vBridge eversince I graduated. Now, It's time for a new adventure! I'm joining the DX-team at Astro full-time!

  • Becoming an Astro maintainer

    Becoming an Astro maintainer

    Since a week, I'm an Astro maintainer, in this post, I describe the process and my start in open source. I also give some insight in what I'm planning to work on.

  • 🍱 Brutal: A theme for Astro

    🍱 Brutal: A theme for Astro

    Brutal is a minimal neobrutalist theme for Astro. It's based on Neobrutalist Web Design, a movement that aims to create websites with a minimalistic and functional design. It has some integrations like Image Optimization, RSS, Sitemap, ready to get your SEO done right.

  • 🎤 Am I an international public speaker now?

    🎤 Am I an international public speaker now?

    A few weeks ago, I gave my first international keynote talk at JSWorld in Amsterdam. In this blogpost, I wanted to share some insights about the conference and my talk.

  • ✨ Building Blog tag index pages in Astro

    ✨ Building Blog tag index pages in Astro

    I wanted to add blog tag collection pages to my website. This way, people could filter on tags I used in my blog posts. Here is a guide on how I implemented it.