How to fix npm ERR! code EEXIST in npm
The EEXIST error occurs when npm tries to create a file or directory that already exists. This often indicates a corrupted state that can be resolved by clearing the affected files.
Quick fix
Fixes npm ERR! code EEXIST
rm -rf node_modules
rm package-lock.json
npm install- Remove node_modules and retry
- Clear npm cache
- Check for running npm processes
- Remove specific file mentioned
rm -rf node_modulesrm package-lock.jsonnpm installnpm ERR! code EEXIST
What this error means
EEXIST is a filesystem error indicating npm tried to create something that already exists. This can happen during installation when there are leftover files from previous failed operations, permission issues, or race conditions with concurrent operations. This differs from package conflict errors - EEXIST is specifically about filesystem operations failing due to existing files.
Typical symptoms
- npm install fails with "file already exists"
- Previous installation was interrupted
- Multiple npm processes running
- Permission denied combined with EEXIST
- Error points to specific file path
- node_modules has leftover files
Common causes
- Interrupted previous installation
- Concurrent npm operations
- Corrupted node_modules
- Symbolic link conflicts
- Global package conflicts
- npm cache corruption
- Manual file system modifications
How to fix "npm ERR! code EEXIST"
Clean install:
rm -rf node_modules
rm package-lock.json
npm installReset npm cache:
npm cache clean --force
npm installEnsure no other npm is running:
ps aux | grep npm
# Kill if found
kill <pid>Delete the conflicting file:
# Error shows: EEXIST /path/to/file
rm -rf /path/to/file
npm installFor global package EEXIST:
# Find global packages location
npm config get prefix
# List and clean
npm ls -g --depth=0
npm uninstall -g problematic-package
npm install -g problematic-packageResolve symlink problems:
# Find broken symlinks in node_modules
find node_modules -type l ! -exec test -e {} \; -print
# Remove them
find node_modules -type l ! -exec test -e {} \; -deleteAdvanced notes
In CI/CD, always start with clean node_modules or use npm ci which clears it automatically. Don't run multiple npm installs in parallel on the same directory. File locking issues can occur on Windows with antivirus scanning node_modules. For persistent issues, check filesystem health (fsck on Linux).
Frequently asked questions
- What does "npm ERR! code EEXIST" mean?
- EEXIST is a filesystem error indicating npm tried to create something that already exists. This can happen during installation when there are leftover files from previous failed operations, permission issues, or race conditions with concurrent operations. This differs from package conflict errors - EEXIST is specifically about filesystem operations failing due to existing files.
- How do I fix "npm ERR! code EEXIST"?
- The EEXIST error occurs when npm tries to create a file or directory that already exists. This often indicates a corrupted state that can be resolved by clearing the affected files.
- What causes "npm ERR! code EEXIST"?
- Interrupted previous installation Concurrent npm operations Corrupted node_modules
- Is the "npm ERR! code EEXIST" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐
- ๐