From 948938858e555f94d73ceb688ef3f54ca48aa251 Mon Sep 17 00:00:00 2001 From: MickLesk <47820557+MickLesk@users.noreply.github.com> Date: Wed, 7 Oct 2026 07:34:30 +0200 Subject: [PATCH] Keep setup_nodejs alive when the caller's directory is gone Nginx Proxy Manager builds OpenResty in a directory it then deletes, so npm started in a cwd that no longer existed and died with uv_cwd (exit 7). The npm upgrade handled that as a warning, but 072081e read the npm major with a bare assignment, which pipefail turned into a fatal error; the error handler then blamed the earlier npm upgrade (ProxmoxVE#17735). Move the cd /opt guard ahead of the first npm call, let the npm_major assignment fail quietly, and clear the silent-failure state once _setup_npm has handled it. --- lib/runtime.func | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/runtime.func b/lib/runtime.func index 50cdd70..ec92209 100644 --- a/lib/runtime.func +++ b/lib/runtime.func @@ -1255,6 +1255,8 @@ _setup_npm() { if ! $STD npm install -g "npm@${target}" 2>/dev/null; then msg_warn "npm stayed at ${before}" + # Handled here; left set, a later unrelated error is reported as this command. + unset _SILENT_FAILED_RC _SILENT_FAILED_CMD _SILENT_FAILED_LINE _SILENT_FAILED_LOG return 0 fi @@ -1272,6 +1274,13 @@ setup_nodejs() { local node_setup_ok_msg="" local NPM_SETUP_VERSION="" + # npm dies with uv_cwd when the caller's directory was deleted, e.g. a build dir. + mkdir -p /opt + cd /opt || { + msg_error "Failed to set safe working directory before npm install" + return 127 + } + # Corepack must run fully non-interactive, or it blocks on "about to download # X. Continue? [Y/n]" -- here and in the calling script's later corepack calls, # which inherit the export. @@ -1406,7 +1415,7 @@ setup_nodejs() { # npm 11+ skips install hooks not covered by allowScripts and still exits 0, # so apps with native addons install with nothing built. local npm_major - npm_major="$(npm -v 2>/dev/null | cut -d. -f1)" + npm_major="$(npm -v 2>/dev/null | cut -d. -f1)" || npm_major="" if [[ "$npm_major" -ge 11 ]]; then $STD npm config set dangerously-allow-all-scripts true --location=global 2>/dev/null || true fi @@ -1444,15 +1453,6 @@ setup_nodejs() { export NODE_OPTIONS="${NODE_OPTIONS:+${NODE_OPTIONS} }--max-old-space-size=${node_heap_mb}" fi - # Ensure valid working directory for npm (avoids uv_cwd error) - if [[ ! -d /opt ]]; then - mkdir -p /opt - fi - cd /opt || { - msg_error "Failed to set safe working directory before npm install" - return 127 - } - # Install global Node modules if [[ -n "$NODE_MODULE" ]] || ((node_major >= 25)); then if ((node_major >= 25)) && [[ ",${NODE_MODULE}," != *",corepack,"* ]] && [[ "$NODE_MODULE" != corepack* ]]; then