ENOTDIR occurs when npm expects a directory path but encounters a file instead. This usually happens due to corrupted cache, a file named 'tmp' in your home directory, or cloud-synced drives.
The ENOTDIR error occurs when npm expects a directory path but encounters a file instead. This typically happens during npm install, when npm tries to access or create a directory in your project structure, cache, or home directory, but finds a regular file at that path instead. The error can originate from corrupted cache entries, conflicting files in system paths, incompatible dependency versions, or a mismatch between what npm expects and what actually exists on disk. It's the opposite of the EISDIR error.
Verify if a 'tmp' file exists in your home directory and remove it if found:
# Check if ~/tmp exists as a file (not directory)
ls -la ~ | grep tmp
# If it's a file, remove it
rm -f ~/tmp
# Verify it's gone
ls -la ~ | grep tmpThis is the most common cause of ENOTDIR errors.
Clean the npm cache and remove package lock files:
# Force clear the npm cache
npm cache clean --force
# Remove existing lock files
rm -f package-lock.json
rm -f yarn.lock
# Verify cache is clean
npm cache verifyCompletely remove your node_modules directory and reinstall from scratch:
# Remove existing node_modules
rm -rf node_modules
# On Windows
rmdir /s /q node_modules
# Reinstall all dependencies
npm install
# Or use clean install for lock file consistency
npm ciCheck your current versions and upgrade if outdated:
# Check current versions
node --version
npm --version
# Upgrade npm to latest
npm install -g npm@latest
# Or upgrade Node.js using nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
nvm install --lts
nvm use --ltsIf using cloud-synced folders, move your project to a local disk:
# Move project from cloud drive to local disk
cp -r ~/CloudDrive/my-project ~/my-project
cd ~/my-project
# Fix permissions (Linux/Mac)
chmod -R u+w .
npm installCloud-synced drives create file locks that interfere with npm's directory operations.
ENOTDIR errors can have platform-specific causes: on Windows, path length limitations (MAX_PATH=260 characters in older versions) can trigger this error. On Linux/Mac, check SELinux policies or file system mount options that might prevent directory creation. In CI/CD environments, ensure the build agent has write permissions to temporary directories and isn't running on network shares. For monorepo projects using workspaces, verify each workspace's node_modules path is correctly isolated.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error