FG
💻 Software🛠️ Developer ToolsMicrosoft

[BUG] npm incorrectly assumes existence of root-owned files on Termux

Fresh5 days ago
Mar 14, 20260 views
Confidence Score55%
55%

Problem

Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] I am using the latest npm Current Behavior On Termux, npm seems to incorrectly assume the existence of files owned by root in the `.npm` directory when trying to either check the outdated global packages, installing a package, or updating a package; nothing in Termux is root-owned by default (and your device must be rooted to even have anything owned by root). This behavior has started occurring since npm v8.12.0. Example: [code block] As mentioned, this can also occur when trying to install or update a package (doesn't matter if it's global or local). Some others seems to be experiencing the same issue: https://github.com/npm/cli/issues/5025, and https://github.com/npm/cli/issues/4451#issuecomment-1152885628 Expected Behavior The expected behavior is for npm to work without assuming the existence of root-owned files that doesn't actually exist, basically to not throw the aforementioned error when checking for outdated global packages, installing/updating global or local packages. Example: [code block] Steps To Reproduce 1. Download, install, and launch Termux from it's official website. 2. Update all installed packages by running `apt update && apt upgrade -y`. 3. Install the latest Node.js LTS release (it doesn't have to be LTS, but for the sake of the example) which bundles npm as well by running `apt install nodejs-lts -y`. 4. Up

Error Output

error when checking for outdated global packages, installing/updating global or local packages.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix npm root-owned file assumption on Termux

Medium Risk

The issue arises because npm v8.12.0 and later versions incorrectly check for the existence of root-owned files in the .npm directory on Termux, which does not have any root-owned files by default. This leads to erroneous error messages when checking for outdated packages or installing/updating packages.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Create a custom npm configuration

    Create a custom npm configuration file that overrides the default behavior of npm regarding file ownership checks.

    bash
    echo 'unsafe-perm=true' > ~/.npmrc
  2. 2

    Set npm log level to verbose

    Set the npm log level to verbose to capture detailed logs that can help in diagnosing any further issues.

    bash
    npm config set loglevel verbose
  3. 3

    Clear npm cache

    Clear the npm cache to remove any potentially corrupted or stale data that could be causing issues.

    bash
    npm cache clean --force
  4. 4

    Test npm functionality

    Run a command to check for outdated global packages or install a package to verify that the issue has been resolved.

    bash
    npm outdated -g
  5. 5

    Revert npm configuration if necessary

    If the issue persists, consider reverting the npm configuration changes made in step 1 by removing the .npmrc file.

    bash
    rm ~/.npmrc

Validation

Confirm the fix worked by running 'npm outdated -g' or installing a package without encountering the root-owned file error. If the commands execute successfully without errors, the issue is resolved.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsrelease-8.xbugneeds-triage