How to fix npm ERR! code ENOCWD npm ERR! Current working directory does not exist in npm
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- Verify the current directory path
- Navigate to a valid directory
- Open a new terminal window if needed
- Restore or recreate the project directory
pwdnpm ERR! code ENOCWDnpm 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
- 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
- The mount point for a remote directory (NFS, SMB) was unmounted while you were still in a subdirectory
- 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"
First, check what directory your terminal thinks it's in and confirm whether it still exists:
pwdThis 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.
Change to a directory that definitely exists. Start with your home directory:
cd ~Or navigate to your projects folder:
cd /path/to/your/projectsRun pwd again to confirm you're in a valid location. The command should succeed without errors.
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:
# Close current terminal, then open a new one
# In the new terminal, verify location:
pwd
lsIf you're using VS Code or another IDE with an integrated terminal, close that terminal pane and open a new one.
If you accidentally deleted your project, you can recreate it. First check if you have a backup or version control:
# 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/projectOnce 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
- ๐npm Official Documentation
- ๐ฌSO: Working directory for npm scripts(Stack Overflow)
- ๐
- ๐