Error Knowledge Base npm ENAMETOOLONG

npm ERR! code ENAMETOOLONG

npm hit ENAMETOOLONG because the generated file path exceeded your operating system path length limit during install or extract.

Fix it fast

Most likely: The project path, cache path, or extracted package path is longer than your OS or filesystem allows.

1. Confirm this is your error
npm ERR! code ENAMETOOLONG
2. Check the cause
pwd
pwd | wc -c
npm config get cache
ls -ld <failing-path>
3. Apply the safe fix
# Move or clone the project to a shorter path, then reinstall from there.
cd ~/code/<short-project-name>
npm install

# If the npm cache path is extremely long, move it to a shorter location.
npm config set cache ~/.npm
4. Verify it works
pwd | wc -c
npm install
Don't use unsafe shortcuts
  • Do not keep retrying from a deeply nested folder, the path will still be too long.
  • Do not use sudo for ENAMETOOLONG, permissions are not the problem.
  • Do not rename random package folders inside node_modules, shorten the project or cache path instead.

What Local Operation Failed

The remote service may be fine. This class of error is usually about what the local machine was allowed to read, write, cache, or execute.

Fix the local path, cache, or permissions

Identify the path npm is failing on (look for the last referenced file path in the error output).

Move the repo to a shorter path (e.g. closer to your home directory) and retry.

Retry after cleaning local state when safe (common:remove node_modules and retry install).

Manual filesystem checks

Look for the last referenced filesystem path in the error output and validate that path exists and is writable.

Why the Local Machine Blocked It

The repo path is too long for the OS/filesystem path length limits.

Verify the Local Path Is Usable Again

Re-run the original command and confirm the filesystem error no longer appears.

If this is a permission fix, confirm new files in node_modules are owned by the expected user.

How npm writes files during install

npm got far enough to read or write local state, but the host filesystem blocked the operation. Ownership drift, read-only mounts, stale caches, full disks, and restrictive permissions all show up in this layer. These are usually local machine or runner problems rather than upstream service problems, so fix the path, ownership, or free space before changing dependency versions.

Prevent Local State Drift

To prevent this, keep npm cache and project directories owned by the build user, avoid running project installs as root unless you know exactly why you need it, and ensure CI runners have enough disk space and sensible file descriptor limits.

Docs and source code

github.com/npm/cli/blob/417daa72b09c5129e7390cd12743ef31bf3ddb83/lib/commands/cache.js

This is a representative filesystem write path during npm operations. Filesystem codes like this are raised by Node/OS when this write fails. - GitHub

        break
      }
      output.standard(`Deleted: ${key}`)
      await cacache.rm.entry(cachePath, key)
      // XXX this could leave other entries without content!
      await cacache.rm.content(cachePath, entry.integrity)
    }

Need help or found a mistake? Contact RepoFlow support for questions.

Join our mailing list