-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
pnpm install/postinstall lifecycle problem #892
Description
pnpm version:
1.14.2
Code to reproduce the issue:
pnpm install in a situation with a postinstall script in package.json
My postinstall script executes another node process (let's call it foobar) that I have written. Unfortunately I cannot provide a self-contained snippet of code from foobar but I can describe what is going wrong.
Last 20 lines or so:
69 info pnpm:root:
added:
id: "registry.npmjs.org/tslint/5.7.0"
name: "tslint"
version: "5.7.0"
dependencyType: "dev"
70 debug pnpm:progress:
status: "installed"
pkgId: "registry.npmjs.org/tslint/5.7.0"
71 info pnpm:root:
added:
id: "registry.npmjs.org/typescript/2.5.2"
name: "typescript"
version: "2.5.2"
dependencyType: "dev"
72 debug pnpm:progress:
status: "installed"
pkgId: "registry.npmjs.org/typescript/2.5.2"
73 info pnpm:summary: {}
74 error pnpm:
message:
code: "ELIFECYCLE"
err:
name: "Error"
message: "Running event postinstall failed with status 1"
code: "ELIFECYCLE"
stack: "Error: Running event postinstall failed with status 1\n at npmRun (/usr/lib/node_modules/pnpm/node_modules/supi/lib/api/install.js:495:21)\n at /usr/lib/node_modules/pnpm/node_modules/supi/lib/api/install.js:108:21\n at next (native)\n at fulfilled (/usr/lib/node_modules/pnpm/node_modules/supi/lib/api/install.js:4:58)"
Expected behavior:
pnpm should install the package without error since a regular npm install works no problem
Actual behavior:
pnpm outputs
ERROR Running event postinstall failed with status 1
Additional information:
node -vprints: 6.11.3npm -vprints: 5.4.1- Windows, OS X, or Linux?: Linux Mint 18.2
I have analysed why this problem occurs simply as follows:
With npm install, preinstall & postinstall scripts (if present in the package.json) are called in the same node process and environment as was started by the original npm install command.
However with pnpm install, pnpm (executing as the original node process) hands the work of pre & post scripts over to npm which is spawned as a child process of pnpm. I found this in install.js:
function npmRun(scriptName, pkgRoot, userAgent) {
const result = runScript_1.sync('npm', ['run', scriptName], {
cwd: pkgRoot,
stdio: 'inherit',
userAgent,
});
if (result.status !== 0) {
const err = new Error(`Running event ${scriptName} from ${pkgRoot} failed with status ${result.status}`);
err['code'] = 'ELIFECYCLE';
throw err;
}
}
The solution for maximum transparency in "emulating" npm is to run package scripts (including pre & post scripts) from inside pnpm in similar manner to how npm does it. Naturally pnpm should also setup the same environment variables as does npm (maybe it does already -- I don't know though I think yarn does for example) also for reasons of transparency.
Nevertheless, pnpm is great work & great concept with the symlinks. The other day I was not able to (rather it was taking forever) compress the babel repo with all plugins node_modules installed as it exceeded 1GB.
I'm providing this issue & analysis to help pnpm become an excellent transparent replacement for npm.