build-image icon indicating copy to clipboard operation
build-image copied to clipboard

npm preinstall and postinstall scripts are not run

Open denis-sokolov opened this issue 4 years ago • 4 comments

npm preinstall and postinstall scripts are not run, resulting in breaking builds that are valid outside of Netlify.

This is caused by our caching mechanism only restoring the node_modules/ directory:

https://github.com/netlify/build-image/blob/d84c79427e8f83c1ba17bcdd7b3fe38059376b68/run-build-functions.sh#L478

And then running npm install conditionally:

https://github.com/netlify/build-image/blob/d84c79427e8f83c1ba17bcdd7b3fe38059376b68/run-build-functions.sh#L149-L153

An existing PR fixes this: #510.

denis-sokolov avatar Feb 02 '21 06:02 denis-sokolov

What's the status on this? I'm running into this on the focal image.

agostbiro avatar Sep 17 '21 14:09 agostbiro

Is it possible to add other folders to be cache in netlify.toml at all?

I haven't seen anything outside the docs though.

Currently breaks builds that use playwright because the browser images are cached outside node_modules.

jonsherrard avatar Sep 28 '21 15:09 jonsherrard

OK idea for peeps out there stuck wthith is issue: I'm just running my "postinstall" command before the npm build command in Netlify config now.

npx [my postinstalll]] && npm run build

jonsherrard avatar Sep 28 '21 15:09 jonsherrard

Just got bit by this breaking our environments because patch-package wasn't run. 😬

mwood23 avatar Nov 19 '21 22:11 mwood23

@jobala Thanks for the PR, a quick review seems to indicate this issue is only fixed for npm users but not for yarn users? Is that correct?

pimlie avatar Oct 24 '22 14:10 pimlie