How to fix npm ERR! code EISDIR npm ERR! EISDIR: illegal operation on a directory in npm

npmINTERMEDIATEHIGHUpdated Dec 5, 2025ยท 204 views

EISDIR occurs when npm attempts to perform a file operation on a path that is actually a directory. This typically happens due to corrupted node_modules or accidentally creating directories with file names.

Quick fix

Fixes EISDIR

npm cache clean --force
npm cache verify
  1. Clear the npm cache and verify it's cleaned
  2. Delete node_modules and package-lock.json, then reinstall
  3. Check for file/directory naming conflicts
  4. Fix npm ownership and permissions (Linux/macOS)
npm โ€” error
npm cache clean --force
npm cache verify
npm ERR! code EISDIR
npm ERR! EISDIR: illegal operation on a directory

What this error means

EISDIR stands for 'Error, Is Directory' and occurs when npm attempts to perform a file operation (like reading or writing) on a path that is actually a directory instead of a file. This commonly happens during npm install, when npm tries to read a configuration file or access a package file, but encounters a directory at that path instead. The error prevents npm from continuing because it cannot complete the file-level operation on a directory object. This is usually caused by corrupted installations or accidental directory creation with file names.

Typical symptoms

  • npm install or npm update fails with 'EISDIR: illegal operation on a directory' message
  • npm commands hang or freeze midway through execution
  • Getting permission/access errors when running npm commands globally
  • Build processes fail when trying to read or write package configuration
  • Multiple npm operations fail consecutively even after restarting

Common causes

  1. Accidentally creating a directory instead of a file (e.g., mkdir .gitignore or mkdir package.json)
  2. Corrupted node_modules directory from interrupted npm install (killed mid-process or network failure)
  3. npm cache containing corrupted entries where directories exist where files should be
  4. Incorrect file path configuration in .npmrc pointing to a directory instead of a file
  5. npm process was interrupted and left the lock file or package references in an invalid state
  6. Node.js/npm version incompatibility causing symlink or file operation issues on Windows

How to fix "npm ERR! code EISDIR npm ERR! EISDIR: illegal operation on a directory"

1Clear the npm cache and verify it's cleaned

Run the following command to force clean your npm cache, then verify it was successful:

bash
npm cache clean --force
npm cache verify

This removes any corrupted cache entries that might be causing the EISDIR error.

2Delete node_modules and package-lock.json, then reinstall

Remove the potentially corrupted node_modules and lock file, then perform a fresh install:

bash
rm -rf node_modules package-lock.json
npm install

On Windows, you may need to use:

cmd
rmdir /s /q node_modules
del package-lock.json
npm install
3Check for file/directory naming conflicts

Verify that you don't have directories created with file names:

bash
# On macOS/Linux - should show files, not directories
ls -la .gitignore .env package.json .npmrc 2>/dev/null

If any of these are directories instead of files, remove them:

bash
rm -rf .gitignore .env package.json .npmrc
# Recreate as files with proper content
echo "" > .gitignore
4Fix npm ownership and permissions (Linux/macOS)

Reset npm directory ownership to your user instead of root:

bash
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) ~/.cache/npm

Alternatively, configure npm to use a local prefix:

bash
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
5Update npm and Node.js to stable versions

Some versions of npm had known EISDIR issues. Update to a stable version:

bash
npm install -g npm@latest
npm --version

Or update Node.js using a version manager:

bash
# Using nvm (macOS/Linux)
nvm install node
nvm use node

Advanced notes

On Windows systems with monorepos, EISDIR can occur when npm attempts to create symlinks in node_modules/.bin but encounters permission issues or conflicting directories. If you're on Windows, try enabling developer mode or running npm with administrator privileges. Additionally, special characters (like #) in folder paths can trigger this error on Windows; rename the parent directory to use only alphanumeric characters and hyphens.

Frequently asked questions

What does "EISDIR" mean?
EISDIR stands for 'Error, Is Directory' and occurs when npm attempts to perform a file operation (like reading or writing) on a path that is actually a directory instead of a file. This commonly happens during npm install, when npm tries to read a configuration file or access a package file, but encounters a directory at that path instead. The error prevents npm from continuing because it cannot complete the file-level operation on a directory object.
How do I fix "EISDIR"?
EISDIR occurs when npm attempts to perform a file operation on a path that is actually a directory. This typically happens due to corrupted node_modules or accidentally creating directories with file names.
What causes "EISDIR"?
Accidentally creating a directory instead of a file (e.g., mkdir .gitignore or mkdir package.json) Corrupted node_modules directory from interrupted npm install (killed mid-process or network failure) npm cache containing corrupted entries where directories exist where files should be
Is the "EISDIR" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading