-
Notifications
You must be signed in to change notification settings - Fork 39
postinstall "cannot run in wd" when working directory does not match the package name (in docker) #49
Comments
I also observed this (in action prepare for me, but whatever), in a Docker in a CI pipeline. Like @amadsen I’m not sure what ckeck the conditions around Note that it is very common in Docker and specifically in CI to execute as root. I think it is a bad practice, but it is very common, even in the official Docker image for node (see this issue). About npm-lifecycle, I wonder if there is not a logic bug around unsafe-perm+user+group:
|
PS: if like me the action is in a child |
@amadsen Thank you so much for digging into this! I’m adding this weird workaround to my package.json: + "__comment": "'name' must match the WORKDIR in Dockerfile used when executing `RUN npm ci`.",
+ "name": "app", Also, if I understand |
What / Why
It is common for a Dockerfile to install an app in a
/app
directory. If the app is a node app and it has a"postinstall"
script (and possibly other lifecycle hooks) it will fail with an error that looks like:Most of the issues found using a search engine will indicate that this is a permissions issue caused by running as root and npm downgrading permissions to nobody. However, this issue will still occur if the "postinstall" script is "exit 0", which should require no permissions. On the other hand, the suggested workaround of setting
--unsafe-perm
works. The relevant lines of code are:(from index.js, lines 86-90)
Note that employing
--unsafe-perm
specifically serves as an escape hatch, though it does not appear to have much to do with permissions on the directory._incorrectWorkingDirectory()
checks to see if the working directory matches the name of the package inpackage.json
.I do not know if this is a bug or intended behavior - it makes sense as a swift heuristic to ensure you are in the expected package - but it is not well documented and conflicts subtly with nodejs.org's recommendations for a Dockerfile.
The text was updated successfully, but these errors were encountered: