How to fix npm ERR! code EISDIR npm ERR! EISDIR: illegal operation on a directory in npm
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- Clear the npm cache and verify it's cleaned
- Delete node_modules and package-lock.json, then reinstall
- Check for file/directory naming conflicts
- Fix npm ownership and permissions (Linux/macOS)
npm cache clean --forcenpm cache verifynpm ERR! code EISDIRnpm 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
- 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
- Incorrect file path configuration in .npmrc pointing to a directory instead of a file
- npm process was interrupted and left the lock file or package references in an invalid state
- 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"
Run the following command to force clean your npm cache, then verify it was successful:
npm cache clean --force
npm cache verifyThis removes any corrupted cache entries that might be causing the EISDIR error.
Remove the potentially corrupted node_modules and lock file, then perform a fresh install:
rm -rf node_modules package-lock.json
npm installOn Windows, you may need to use:
rmdir /s /q node_modules
del package-lock.json
npm installVerify that you don't have directories created with file names:
# On macOS/Linux - should show files, not directories
ls -la .gitignore .env package.json .npmrc 2>/dev/nullIf any of these are directories instead of files, remove them:
rm -rf .gitignore .env package.json .npmrc
# Recreate as files with proper content
echo "" > .gitignoreReset npm directory ownership to your user instead of root:
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) ~/.cache/npmAlternatively, configure npm to use a local prefix:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATHSome versions of npm had known EISDIR issues. Update to a stable version:
npm install -g npm@latest
npm --versionOr update Node.js using a version manager:
# Using nvm (macOS/Linux)
nvm install node
nvm use nodeAdvanced 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
- ๐npm Official Documentation
- ๐Docs: npm CLI(Official Docs)
- ๐GitHub: npm issues(GitHub)
- ๐ฌSO: npm EISDIR errors(Stack Overflow)