Another suggestion that is probably an even better option is to put this in netlify.toml file, as it is not a “secret variable” and as this step can be easily omitted in case you have to set up a site again.
[build.environment]
PNPM_FLAGS = "--shamefully-hoist"