pnpm: Error: spawn E2BIG when running postinstall scripts
When upgrading from version 7.18.2 to 7.19.0, pnpm install errors out when running the postinstall scripts with the following error:
node:internal/child_process:413
throw errnoException(err, 'spawn');
^
Error: spawn E2BIG
at ChildProcess.spawn (node:internal/child_process:413:11)
at spawn (node:child_process:713:9)
at spawn (/usr/local/lib/node_modules/pnpm/dist/pnpm.cjs:104514:19)
at runCmd_ (/usr/local/lib/node_modules/pnpm/dist/pnpm.cjs:117817:20)
at /usr/local/lib/node_modules/pnpm/dist/pnpm.cjs:117761:11
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
errno: -7,
code: 'E2BIG',
syscall: 'spawn'
}
It doesn’t seem to matter which postinstall script is run, any from any dependency or our own one will suffice.
Our .npmrc file is as follows
node-linker=hoisted
shared-workspace-lockfile = false
We need node-linker=hoisted as we have some angular projects in our mono-repo. Unsetting this seems to fix the problem but breaks the application builds.
These to pull requests seem that they might be related (included in the 7.19 release):
pnpm version: 7.19.0 and upwards
Additional information:
node -vprints: 16.17.1- Windows, macOS, or Linux?: Tested on MacOS and on linux (
Linux e545ebd99b57 4.19.0-17-amd64 #1 SMP Debian 4.19.194-1 (2021-06-10) x86_64 x86_64 x86_64 GNU/Linux)
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 18
- Comments: 20 (3 by maintainers)
This seems to be caused by PATH environment variable (generated somewhere in npm-lifecycle package I think) that contains paths to all .bin folders in all nested node_modules?
It seems to be caused by this parameter that contains all those paths https://github.com/pnpm/pnpm/blob/f5121500ee9b23d71ee5618f3afe296ef56640da/exec/lifecycle/src/runLifecycleHook.ts#L66 (in our case about 3500 entries). Those paths look like this
Hope this will help to fix this issue.
This error was sometimes caused by big values in some specific
npm_config_env variables, which we stopped populating in pnpm v10.🙇 oh great @zkochan just wanted to bump this issue, as I’m currently running into it again