How to fix npm ERR! code ENOCWD npm ERR! Current working directory does not exist in npm

npmBEGINNERMEDIUMUpdated Dec 5, 2025ยท 101 views

The ENOCWD error occurs when npm can't access your current working directory because it has been deleted, moved, or renamed while your terminal session was still open. Fix it by navigating to a valid directory.

Quick fix

Fixes npm ERR! code ENOCWD npm ERR! Current working directory does not exist

pwd
  1. Verify the current directory path
  2. Navigate to a valid directory
  3. Open a new terminal window if needed
  4. Restore or recreate the project directory
npm โ€” error
pwd
npm ERR! code ENOCWD
npm ERR! Current working directory does not exist

What this error means

This error means that npm tried to execute a command in your current working directory, but the directory path is no longer valid or accessible. This typically happens when a folder is deleted or renamed by another process (file manager, script, or another terminal) while you still have an active shell session in that directory. Your shell session retains the old directory path in memory, but when npm tries to verify the directory exists, it fails because the path is now invalid. The operating system returns an ENOCWD (Error: NO Current Working Directory) error code.

Typical symptoms

  • You see 'npm ERR! code ENOCWD' followed by 'Current working directory does not exist'
  • The error appears after deleting or renaming a project folder in your file manager or another terminal
  • npm commands fail immediately without attempting the operation
  • The error occurs even though you haven't changed directories in your current terminal
  • New terminals work fine, but your existing terminal window shows the error

Common causes

  1. The project directory was deleted, moved, or renamed in your file manager or by another terminal while your current session was still open
  2. A build script, git operation, or other automated process removed the directory from disk
  3. The directory was deleted by another user or process on a shared system
  4. The mount point for a remote directory (NFS, SMB) was unmounted while you were still in a subdirectory
  5. The parent directory was deleted, making the current directory inaccessible

How to fix "npm ERR! code ENOCWD npm ERR! Current working directory does not exist"

1Verify the current directory path

First, check what directory your terminal thinks it's in and confirm whether it still exists:

bash
pwd

This will print the current working directory path. If the output shows a path that doesn't exist (e.g., /home/user/my-deleted-project), the directory has been removed.

2Navigate to a valid directory

Change to a directory that definitely exists. Start with your home directory:

bash
cd ~

Or navigate to your projects folder:

bash
cd /path/to/your/projects

Run pwd again to confirm you're in a valid location. The command should succeed without errors.

3Open a new terminal window if needed

If the error persists, close the current terminal and open a new one. This forces your shell to start in a default directory (usually your home directory) rather than retaining the old invalid path:

bash
# Close current terminal, then open a new one
# In the new terminal, verify location:
pwd
ls

If you're using VS Code or another IDE with an integrated terminal, close that terminal pane and open a new one.

4Restore or recreate the project directory

If you accidentally deleted your project, you can recreate it. First check if you have a backup or version control:

bash
# If you have a git remote, clone it back
git clone <your-repository-url> my-project
cd my-project

# Or recreate the directory structure manually
mkdir -p /path/to/your/project
cd /path/to/your/project

Once you're in a valid project directory, npm commands should work normally.

Advanced notes

This error is particularly common in development environments where multiple processes interact with the file system. If you're working in a Docker container, ensure your Dockerfile properly sets the WORKDIR before running npm commands. On Windows with WSL, ensure the mounted directories haven't been unmounted. For CI/CD pipelines, verify that cleanup scripts don't remove the working directory while jobs are still running.

Frequently asked questions

What does "npm ERR! code ENOCWD npm ERR! Current working directory does not exist" mean?
This error means that npm tried to execute a command in your current working directory, but the directory path is no longer valid or accessible. This typically happens when a folder is deleted or renamed by another process (file manager, script, or another terminal) while you still have an active shell session in that directory. Your shell session retains the old directory path in memory, but when npm tries to verify the directory exists, it fails because the path is now invalid.
How do I fix "npm ERR! code ENOCWD npm ERR! Current working directory does not exist"?
The ENOCWD error occurs when npm can't access your current working directory because it has been deleted, moved, or renamed while your terminal session was still open. Fix it by navigating to a valid directory.
What causes "npm ERR! code ENOCWD npm ERR! Current working directory does not exist"?
The project directory was deleted, moved, or renamed in your file manager or by another terminal while your current session was still open A build script, git operation, or other automated process removed the directory from disk The directory was deleted by another user or process on a shared system
Is the "npm ERR! code ENOCWD npm ERR! Current working directory does not exist" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading