How to fix npm ERR! code ENOTDIR npm ERR! ENOTDIR: not a directory in npm

npmBEGINNERMEDIUMUpdated Dec 5, 2025ยท 190 views

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.

Quick fix

Fixes ENOTDIR

# 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 tmp
  1. Check for and remove conflicting tmp file
  2. Clear npm cache and remove lock files
  3. Remove node_modules and reinstall dependencies
  4. Upgrade to a modern Node.js and npm version
npm โ€” error
# 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 tmp
npm ERR! code ENOTDIR
npm ERR! ENOTDIR: not a directory

What this error means

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.

Typical symptoms

  • npm install command fails immediately with 'ENOTDIR: not a directory' error
  • Specific npm operations like npm ci or npm update consistently fail at the same point
  • Error message references a path like ~/.npm, ~/tmp, or within node_modules that should be a directory
  • Installation works from command line but fails in CI/CD pipelines
  • After removing node_modules, reinstalling triggers the same error repeatedly

Common causes

  1. A file named 'tmp' exists as a regular file in the home directory (~/) instead of being a directory
  2. Corrupted or locked npm cache containing invalid file entries that conflict with expected directory structures
  3. Incompatible or outdated npm and Node.js versions with packages expecting newer directory structures
  4. Dependencies with incorrect or missing version specifications causing extraction failures
  5. Installing npm packages on cloud-synced drives (Google Drive, OneDrive, iCloud) that create file locks
  6. Partially downloaded or interrupted npm installations leaving incomplete directory structures

How to fix "npm ERR! code ENOTDIR npm ERR! ENOTDIR: not a directory"

1Check for and remove conflicting tmp file

Verify if a 'tmp' file exists in your home directory and remove it if found:

bash
# 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 tmp

This is the most common cause of ENOTDIR errors.

2Clear npm cache and remove lock files

Clean the npm cache and remove package lock files:

bash
# 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 verify
3Remove node_modules and reinstall dependencies

Completely remove your node_modules directory and reinstall from scratch:

bash
# 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 ci
4Upgrade to a modern Node.js and npm version

Check your current versions and upgrade if outdated:

bash
# 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 --lts
5Move project to local disk if on cloud storage

If using cloud-synced folders, move your project to a local disk:

bash
# 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 install

Cloud-synced drives create file locks that interfere with npm's directory operations.

Advanced notes

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.

Frequently asked questions

What does "ENOTDIR" mean?
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.
How do I fix "ENOTDIR"?
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.
What causes "ENOTDIR"?
A file named 'tmp' exists as a regular file in the home directory (~/) instead of being a directory Corrupted or locked npm cache containing invalid file entries that conflict with expected directory structures Incompatible or outdated npm and Node.js versions with packages expecting newer directory structures
Is the "ENOTDIR" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading