npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.33k stars 3.06k forks source link

postinstall not being executed for pngquant-bin on MacOS #2853

Open llamerr opened 3 years ago

llamerr commented 3 years ago

Current Behavior:

One of subdependencies is pngquant-bin which have postinstall script which is not being executed now

Expected Behavior:

postinstall should execute and generate node_modules/pngquant-bin/vendor/pngquant file

Steps To Reproduce:

Do npm ci for this package.json file https://github.com/llamerr/npm-postinstall-bug and check content of ls node_modules/pngquant-bin/vendor/ as of now, it only contains source folder, but pngquant file is missing

No errors or warnings reported by npm during install from what I see, https://github.com/llamerr/npm-postinstall-bug/blob/master/install.log

It probably started happening after yesterday's upgrade on MacOS. First after I did rm -rf node_modules and npm ci everything broke, so I checked updates and noticed new, upgraded my MacOS, brew, and command line tools. After everything started working again, I still was getting errors in my code which lead me to pngquant bin being missing. I'm using node from nvm if it matters, not sure if I did global packages update (I think I did? At least for some of them, will re-try now), but seems other stuff working fine.

Environment:

OS: MacOS Big Sur 11.2.3 (20D91)

➜ npm-postinstall-bug git:(master) node -v v14.15.3

➜ npm-postinstall-bug git:(master) npm -v 7.6.2

➜ npm-postinstall-bug git:(master) pkgutil --pkg-info=com.apple.pkg.CLTools_Executables

package-id: com.apple.pkg.CLTools_Executables version: 12.4.0.0.1.1610135815 volume: / location: / install-time: 1615403944 groups: com.apple.FindSystemFiles.pkg-group

llamerr commented 3 years ago

I removed package-lock.json and did npm i --force again (some packages are incompatible, but seem to work fine) and it did postinstall properly this time. Should I close it or is it still a bug?

burtonator commented 3 years ago

@llamerr why should this bug be removed ? I'm having the same issue. on Linux (our CI system) and MacOS.

postinstall just doesn't seem to be reliably executed in v7. I'm noticing this across dozens of projects including eslint and electron.

llamerr commented 3 years ago

@burtonator I was thinking the issue was that I used force install, so maybe there were some incompatibilities, but that's still strange since I did not see any errors or warnings if I recall correctly.

burtonator commented 3 years ago

@llamerr I'm seeing this happen with other packages regardless of ci or install and regardless of package-lock.json or none.

This is happening with electron, eslint, etc. Completely breaking our workflow.

v6 has some serious bugs that we had to avoid so now we're on v7 but there are bugs on v7 we have to avoid too.

darcyclarke commented 3 years ago

@llamerr can you try replicating this problem on the latest version of npm? (ie. npm i -g npm) We had a bug at one point in an earlier v7 where package-lock.json was missing some context which could have effected executing lifecycle scripts.

llamerr commented 3 years ago

I tried to reproduce it before upgrading, my current versions are:

➜  npm-postinstall-bug git:(master) node -v
v14.16.0
➜  npm-postinstall-bug git:(master) npm -v
6.14.11

and it seems on those versions it's already not reproducing, means working fine

hm... actually I did not remove node_modules before trying it, but checking log, it seems that was done by npm

➜  npm-postinstall-bug git:(master) npm ci
npm WARN prepare removing existing node_modules/ before installation

after npm update (can nvm be related?)

➜  npm-postinstall-bug git:(master) npm i -g npm
/Users/alexey.lukin/.nvm/versions/node/v14.16.0/bin/npm -> /Users/alexey.lukin/.nvm/versions/node/v14.16.0/lib/node_modules/npm/bin/npm-cli.js
/Users/alexey.lukin/.nvm/versions/node/v14.16.0/bin/npx -> /Users/alexey.lukin/.nvm/versions/node/v14.16.0/lib/node_modules/npm/bin/npx-cli.js
+ npm@7.12.0
added 60 packages from 23 contributors, removed 241 packages and updated 194 packages in 6.705s

versions now are

➜  npm-postinstall-bug git:(master) node -v
v14.16.0
➜  npm-postinstall-bug git:(master) npm -v
7.12.0

and now bug is reproduced:

➜  npm-postinstall-bug git:(master) ls node_modules/pngquant-bin/vendor/
source

actually I see that on first try today it was 6.14.11, probably I downgraded it during this time somehow, not sure

MrTibbles commented 1 year ago

I too am having issues with the postinstall script of a sub-dependency not being called. However when ran with yarn it works as expected.

I have package A that has package B listed as a dependency, package B has a post install hook defined. When package B is installed directly by a project the post install script fires as expected, however when package A is installed the post install script for package B is not being called. I have passed --foreground-scripts to ensure nothing is being missed.

I was initially encountering this on npm v8, so i updated to v9, but i am still facing the exact same issue.

Node version: v18.14.2 npm version: 9.5.0 OS: Mac Ventura 13.0.1 (22A400)