-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'
due to NPM writing to /layers
at runtime
#800
Comments
@Crazybun0422 - Looks like something is trying to create a directory in |
I did npm install when initializing the app, however, this error is reported as I did execute 'node ./web/index.js'. that's difficult to understand why, and this error just appeared when I pull this image last time. so I just guess all these images actually released bug existing. |
heroku/builder-classic:22 Only this version is work. I tested times of them but seems like all the APIs are deprecated, how I could modify my app to satisy these? |
@Crazybun0422 I highly suggest |
@Crazybun0422 Have you had a chance to try the above? Also, could you provide more information on when this stopped working? The build log from the last successful build would be very helpful. |
(I've transferred this issue from https://github.com/heroku/cnb-builder-images to https://github.com/heroku/buildpacks-nodejs) |
@joshwlewis @colincasey So I can reproduce this easily using the Node.js getting started guide, if I switch to a different user at runtime (that doesn't have write access to It looks like NPM or something is trying to write out a cache to the For simplicity in this repo I've used the $ git clone https://github.com/heroku/node-js-getting-started && cd node-js-getting-started
$ pack build node-test
...
$ docker run --rm -it --user nobody --env npm_config_loglevel=silly node-test
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
npm verb cli /layers/heroku_nodejs-engine/dist/bin/node /layers/heroku_nodejs-engine/dist/bin/npm
npm info using npm@10.2.4
npm info using node@v20.11.1
npm verb cache could not create cache: Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'
npm verb logfile could not create logs-dir: Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'
npm verb title npm start
npm verb argv "start"
npm verb logfile logs-max:10 dir:/layers/heroku_nodejs-npm-install/npm_cache/_logs/2024-03-18T10_02_30_443Z-
npm verb logfile could not be created: Error: ENOENT: no such file or directory, open '/layers/heroku_nodejs-npm-install/npm_cache/_logs/2024-03-18T10_02_30_443Z-debug-0.log'
npm verb logfile no logfile created
npm sill logfile done cleaning log files
> node-js-getting-started@0.3.0 start
> node index.js
npm verb stack Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'
npm verb cwd /workspace
npm verb Linux 6.6.16-linuxkit
npm verb node v20.11.1
npm verb npm v10.2.4
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /layers/heroku_nodejs-npm-install
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'
npm ERR! [Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/layers/heroku_nodejs-npm-install'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm verb exit -13
npm verb unfinished npm timer command:start 1710756150561
npm verb unfinished npm timer command:run-script 1710756150568
npm verb code -13
npm ERR! Log files were not written due to an error writing to the directory: /layers/heroku_nodejs-npm-install/npm_cache/_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal |
Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'
due to NPM writing to /layers
Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'
due to NPM writing to /layers
Error: EACCES: permission denied, mkdir '/layers/heroku_nodejs-npm-install'
due to NPM writing to /layers
at runtime
Interesting find @edmorley. I'll play around with this reproduction later today but it seems like the culprit here may be npm's logging. |
I don't think the logging is the root issue, the inability to write a cache is. It's just that when the original error occurs, NPM tries to create a log file about it, which also fails, but a previous error has occurred either way. |
The cache would have been written during the build phase. It's surprising to me that |
Looks like the cache layer does get written correctly during the build phase, but is not available at runtime, (by design - it reduces image size to leave it out). A few options I can think of:
|
@joshwlewis @edmorley I was hoping it would be something simple like the cache folder doesn't exist at launch so the logging fails but you're right, the logging failures are not the main cause. The I also shelled into the built image and tried the following commands with no issue:
So maybe there's something specific about the |
@joshwlewis @edmorley the underlying cause here seems to be the update-notifier causing this issue. When an npm command is executed, an update check is registered to execute asynchronously. The notifier makes a request out to the npm registry for the Following the reproduction steps that @edmorley outlined above with a slight alteration to disable the update notifier works:
I'm going to file an issue with npm, but in the meantime, we should consider:
|
Link to existing issue with |
It looks like the default user change for Fly.io (that was what triggered this issue being opened) was unintentional, and was fixed in: In addition, the NPM fix for the update-notifier trying to initialise the cache has been fixed in NPM. As such, building the Node.js getting started guide with a read-only filesystem (via the Longer term we should probably test that all of our buildpacks work with read-only mode (when combined with an app that does the right thing; we can't do anything about app code/app dependencies that try to write to places they shouldn't). xref: heroku/base-images#268 For Node.js specifically, is there any other follow-up work here? For example, it sounded like NPM tries to write logs to a read-only directory in the case of an error occurring. Presumably errors can occur for reasons other than the update-notifier not being able to write to the cache (for example if |
I reckon these Images are indeed bug existing.
The text was updated successfully, but these errors were encountered: