Skip to content

fix(cli): fall back to a writable npm prefix when the global one is read-only - #1070

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-fall-back-to-a-writable-npm-4023bd
Draft

fix(cli): fall back to a writable npm prefix when the global one is read-only#1070
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixcli-fall-back-to-a-writable-npm-4023bd

Conversation

@posthog

@posthog posthog Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Problem

  • Debug-symbol upload silently never works on Nix-managed Node, and the handled failure lands in error tracking as an exception.
  • A Nix-provisioned Node lives in the read-only /nix/store, which is npm's global prefix, so npm install --global @posthog/cli@latest dies with EACCES. installOrUpdatePostHogCli had no fallback.
  • The source maps flow then finished looking successful, but the user's release build could never upload debug symbols. The same unguarded install backs wizard cli add.
  • The pre-install reported this handled, environmental failure to error tracking with captureException — noise, not a bug.

Changes

  • Retry against a user-writable prefix. On a permission error (EACCES / EROFS / EPERM / "permission denied"), installOrUpdatePostHogCli retries with npm install --global --prefix ~/.posthog and prepends the fallback bin directory to PATH, so later posthog-cli spawns resolve. Both call sites — the source maps pre-install and wizard cli add — share this one guarded install.
  • Stop reporting a handled failure as an exception. The source maps pre-install keeps the user-facing warning and records a wizardCapture event, and no longer calls captureException (mirrors #456 for external tool errors). The now-dead errorObject field on CliInstallResult is removed.

Test plan

  • pnpm build && pnpm test — 1740 tests pass.
  • New unit tests cover: retry on a permission error (asserts the --prefix args and the PATH entry), no retry on a non-permission failure, and surfacing the retry failure when the fallback prefix also fails.

LLM context

Authored by a PostHog coding agent. errorObject was removed because its only consumer was the captureException call this PR deletes.


Created with PostHog Desktop from this inbox report.

…ead-only

On a Nix-provisioned machine, Node lives in the read-only `/nix/store`, which
is npm's global prefix, so `npm install --global @posthog/cli@latest` dies with
`EACCES`. The source maps flow then finished looking successful while the
release build could never upload debug symbols.

`installOrUpdatePostHogCli` now retries against a user-writable prefix
(`~/.posthog`) on a permission error and puts its `bin` directory on PATH so
the later `posthog-cli` spawns resolve. The same guarded install backs
`wizard cli add`.

The source maps pre-install no longer reports a handled, environmental failure
to error tracking with `captureException`; it keeps the user-facing warning and
records a `wizardCapture` event instead.

Generated-By: PostHog Code
Task-Id: a077ce16-593d-4697-bc50-b7d6b30e24b1
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci revenue
  • /wizard-ci self-driving

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/groq
  • /wizard-ci ai-observability/manual-capture
Show more apps
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit

Results will be posted here when complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants