npm debug log missing when home directory is read‑only in CI
0 reputation · 17 Aug 2023, 04:43 UTC
0 reputation · 17 Aug 2023, 04:43 UTC
The goal is to obtain the npm debug log that is automatically written when a command fails, so that the root cause of a deployment step can be diagnosed.
In CI runners the $HOME directory may be mounted read‑only or recreated each job, and the log location changes between npm 6 (npm-debug.log in the current working directory) and npm 7+ (~/.npm/_logs/<timestamp>.log). When the home directory cannot be written, it is unclear whether npm falls back to another location or suppresses the log entirely.
What is the expected behavior of npm’s debug‑log writer when the configured log directory is not writable? Does npm emit an error about the missing log file, or does it silently skip log creation? How can a CI pipeline reliably locate or force the log to a writable path without modifying the application code?
When npm cannot open its debug‑log file for writing, it writes an error message to stderr (e.g., "Failed to write debug log: EACCES: permission denied, open …") and continues the command. It does not silently skip log creation nor fall back to another location.
logfile (default: ~/.npm/_logs/.log for npm ≥ 7, npm-debug.log in the current working directory for npm < 6).npm_config_logfile or by running npm config set logfile before the failing command.In a CI runner where $HOME is mounted read‑only, the default log directory (~/.npm/_logs) is unwritable. npm therefore fails to open the log file, prints the warning to stderr, and no debug log is produced unless the logfile config is explicitly redirected to a writable location.
npm --version) – this determines the default path.export npm_config_logfile=/tmp/npm-debug.log
/tmp/npm-debug.log) for the debug output.To tailor the recommendation to your environment, please confirm the npm version you are running (output of npm --version).
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.