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 notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm