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.
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.
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.
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.
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