Error Knowledge Base NPM EPERM

npm ERR! code EPERM

npm failed due to an operation not permitted by the OS (EPERM).

Affected versions: All supported npm versions.

What This Error Means

npm failed due to an operation not permitted by the OS (EPERM).

How to Fix It

  1. Identify the path npm is failing on (look for the last referenced file path in the error output).
  2. Avoid sudo npm install for project installs. It often causes mixed ownership inside node_modules.
  3. Fix ownership of npm cache and project folder (example: sudo chown -R $(whoami) ~/.npm).
  4. If the error is for global installs, use a user-writable prefix (example: npm config set prefix ~/.npm-global) and ensure PATH includes it.
  5. Retry after cleaning local state when safe (common: remove node_modules and retry install).

Why It Happens

  • The current user does not have permission to write to the project folder, npm cache, or global prefix.

How to Verify

  1. Re-run the original command and confirm the filesystem error no longer appears.
  2. If this is a permission fix, confirm new files in node_modules are owned by the expected user.

Manual filesystem checks

  1. Check ownership/permissions for the failing path: ls -la <path>.

Common CLI Output

npm ERR! code EPERM
npm ERR! errno EPERM

Prevention Tips

  • 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.
  • Ensure CI runners have enough disk space and sensible file descriptor limits.

Where This Can Be Triggered

github.com/npm/cli/blob/417daa72b09c5129e7390cd12743ef31bf3ddb83/workspaces/libnpmexec/lib/with-lock.js

Open-source npm CLI code reference tied to this error code. - GitHub

    try {
      await fs.mkdir(lockPath)
    } catch (err) {
      if (err.code !== 'EEXIST' && err.code !== 'EBUSY' && err.code !== 'EPERM') {
        throw err
      }

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

Join our mailing list