Using Pnpm with Nextjs

I am having trouble using pnpm with nextjs on netlify. I followed the recommendations here Using pnpm and pnpm workspaces and Feature request: Add PNPM support · Issue #1633 · netlify/build · GitHub which were initially working fine with next-on-netlify. Now even that seems to be breaking.

With the next build plugin, I run into an error that says next is not installed on the prebuild by the plugin, which runs before my custom prebuild which installs the packages.

Steps to reproduce the behaviour:

  1. Create a next project with pnpm and the below netlify.toml
  2. Push to netlify and build without cache. (I think it worked the first few times for me because it has next cached from yarn before, we just migrated over)
  3. Should see the error in the console

This repo can be used to reproduce the bug GitHub - CryogenicPlanet/netlify-next-prebuild-bug

// netlify.toml
  command   = "npm run build"
  publish   = "out"
  package = "@netlify/plugin-nextjs"

Kind of blocked on this bug because netlify is not able to build our codebase and don’t want to move back to yarn as it is occupying way too much space.

I posted this same bug on github too Prebuild error when using pnpm · Issue #219 · netlify/netlify-plugin-nextjs · GitHub would love any recommendations to work around this

hi there, sorry to be slow to respond - we wanted a chance to check with our nextjs experts before responding. Unfortunately, this isn’t possible the way you are hoping - but, we have made a note of your issue and your best bet is to keep an eye on that to see if there is any movement on this. Sorry I don’t have better news!

We actually hacked together a solution internally for now by creating a plugin that runs before the main next plugin

If anyone else is blocked on this, feel free to use it below

Hello @CryogenicPlanet :wave: thank you so much for letting us know! This will definitely be helpful for future Forums members who encounter the same situation :netliconfetti:

1 Like