From 7f4583d0fe41cb28de59e9b8e01722d8c58082d2 Mon Sep 17 00:00:00 2001 From: gavrielc Date: Thu, 23 Apr 2026 10:50:19 +0300 Subject: [PATCH] fix(setup): add npm global prefix bin to PATH after fallback install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When corepack enable fails with EACCES (common when Node is installed to a system-writable prefix like /usr/local that the user doesn't own), we fall back to `npm install -g pnpm`. But npm's global prefix isn't always on the shell's PATH — users often set `npm config set prefix ~/.npm-global` to avoid sudo, and the resulting bin dir isn't picked up by `command -v`. Install succeeded, but pnpm "wasn't there" for the follow-up `pnpm install`. Now after the npm fallback we query `npm config get prefix` and prepend `/bin` to PATH. Mirror the same lookup in nanoclaw.sh right before `exec pnpm run setup:auto` — setup.sh's PATH mutation doesn't propagate back, and the hand-off needs pnpm visible too. Co-Authored-By: Claude Opus 4.7 (1M context) --- nanoclaw.sh | 11 +++++++++++ setup.sh | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/nanoclaw.sh b/nanoclaw.sh index 0bf193873..f8b58e7cb 100755 --- a/nanoclaw.sh +++ b/nanoclaw.sh @@ -245,6 +245,17 @@ fi # wipe it. export NANOCLAW_BOOTSTRAPPED=1 +# setup.sh may have just installed pnpm via npm into a prefix that's not on +# our PATH (custom `npm config set prefix`, or the default prefix missing +# from the shell's login PATH). Its PATH mutation doesn't propagate back +# to us — so replay the same lookup here before the exec. +if ! command -v pnpm >/dev/null 2>&1 && command -v npm >/dev/null 2>&1; then + NPM_PREFIX="$(npm config get prefix 2>/dev/null)" + if [ -n "$NPM_PREFIX" ] && [ -x "$NPM_PREFIX/bin/pnpm" ]; then + export PATH="$NPM_PREFIX/bin:$PATH" + fi +fi + # --silent suppresses pnpm's `> nanoclaw@2.0.0 setup:auto / > tsx setup/auto.ts` # preamble so the flow continues visually from "Basics installed" straight # into setup:auto's spinner. exec so signals (Ctrl-C) propagate directly. diff --git a/setup.sh b/setup.sh index e11e073e1..9ca73c1bb 100755 --- a/setup.sh +++ b/setup.sh @@ -120,6 +120,20 @@ install_deps() { || true fi + # `npm install -g` writes to npm's global prefix, which isn't always on the + # shell PATH — common on macOS where the user has `npm config set prefix + # ~/.npm-global` to avoid sudo, or on Linux where /usr/local/bin isn't in + # PATH. Discover the prefix and prepend its bin dir so `command -v pnpm` + # sees the new install. + if ! command -v pnpm >/dev/null 2>&1 && command -v npm >/dev/null 2>&1; then + local npm_prefix + npm_prefix=$(npm config get prefix 2>/dev/null) + if [ -n "$npm_prefix" ] && [ -x "$npm_prefix/bin/pnpm" ]; then + export PATH="$npm_prefix/bin:$PATH" + log "Prepended npm prefix bin to PATH: $npm_prefix/bin" + fi + fi + if ! command -v pnpm >/dev/null 2>&1; then log "pnpm not on PATH after corepack + npm fallback" return