Build fails because of PNPM version 7

Netlify site name: https://avi12-website.netlify.app
Ever since PNPM’s requirement with version 7 to support Node 14 or above, my build fails, as Netlify only supports Node 12
I’m wondering whether I should switch to NPM or not in the meantime.

Hi there, node 14+ is not a problem, you’ll just need to set it explicitly.

From our documentation:

Thanks! I successfully set NODE_VERSION=16.15.0
However, now I’m having a different issue:

Did you try doing what the error suggests? That is, add one of the flags to npm?

You can do it as explained here: Manage build dependencies | Netlify Docs

What about the npm ERR! EEXIST: file already exists, mkdir '/dev/null' part?

After switching to Node 14, I get a different error:

Basically, despite the onPreBuild script installing PNPM, it fails to run.

module.exports = {
  async onPreBuild({ utils: { build, run, status } }) {
    try {
      if (process.env.CI) {
        await run.command("npx pnpm install -r --shamefully-hoist --store=node_modules/.pnpm-store");
      } else {
        status.show({ summary: "CI is false, skipping pnpm install." });
      }

      status.show({ summary: "Installed pnpm!" });
    } catch (e) {
      build.failBuild(`An error occurred while installing pnpm: ${e.message}`);
    }
  }
};

I ended up fixing the issue by:

  1. changing the onPreBuild script to
    module.exports = {
      async onPreBuild({ utils: { build, run, status } }) {
        try {
          if (process.env.CI) {
            await run.command("npx pnpm i --shamefully-hoist");
          } else {
            status.show({ summary: "CI is false, skipping pnpm install." });
          }
    
          status.show({ summary: "Installed pnpm!" });
        } catch (e) {
          build.failBuild(`An error occurred while installing pnpm: ${e.message}`);
        }
      }
    };
    
    
  2. setting in the netlify.toml
    [build]
      command = "npx pnpm build"
    ...
    
  3. setting an environment variable: NODE_VERSION=14
1 Like