How to fix npm ERR! code ENOPROJECT npm ERR! Not a project directory (no package.json found) in npm

npmBEGINNERMEDIUMUpdated Dec 5, 2025ยท 136 views

This error occurs when npm commands are run in a directory without a package.json file. It means you're in the wrong directory or haven't initialized your Node.js project yet.

Quick fix

Fixes npm ERR! code ENOPROJECT npm ERR! Not a project directory (no package.json found)

pwd
ls -la
  1. Check your current working directory
  2. Navigate to your project root directory
  3. Create package.json if it doesn't exist
  4. Verify the clone is complete (for cloned repositories)
npm โ€” error
pwd
ls -la
npm ERR! code ENOPROJECT
npm ERR! Not a project directory (no package.json found)

What this error means

The ENOPROJECT error indicates that npm cannot find a valid project directory because there is no package.json file present. This file is the foundation of any Node.js project and tells npm what your project is, what dependencies it has, and what scripts can be executed. When npm looks for this file in your current directory and doesn't find it, it treats the location as not a valid project directory. This error is npm's way of protecting you from accidentally running commands in the wrong location, which could create or modify files where you don't intend them to be. Most npm commands (like install, start, run, publish) require a package.json file to function properly.

Typical symptoms

  • npm install, npm start, or npm run commands fail with ENOPROJECT message
  • You can see the package.json file exists but npm still can't find it
  • The error mentions 'Not a project directory (no package.json found)'
  • Running npm in a parent or sibling directory instead of the project root
  • Recently cloned a repository but npm commands don't work

Common causes

  1. Current working directory is not the project root (you're in a subdirectory or parent folder)
  2. The package.json file was accidentally deleted or never created
  3. Repository clone was incomplete or corrupted, missing the package.json file
  4. Running npm from a system directory or location outside your project
  5. IDE or terminal opened in the wrong folder context

How to fix "npm ERR! code ENOPROJECT npm ERR! Not a project directory (no package.json found)"

1Check your current working directory

First, verify which directory you're currently in. Your terminal should show the path, but you can also list files to confirm.

On Mac/Linux:

bash
pwd
ls -la

On Windows:

bash
cd
dir

Look for package.json in the output. If you don't see it, you're in the wrong directory.

2Navigate to your project root directory

Change to the root directory of your Node.js project where package.json is located.

bash
cd /path/to/your/project

Replace /path/to/your/project with the actual path to your project. For example:

bash
cd ~/Documents/my-app
cd /Users/username/Projects/react-app

After navigating, run ls (or dir on Windows) to confirm you see package.json.

3Create package.json if it doesn't exist

If you're in the correct project directory but package.json is missing, create it with npm init.

Interactive setup:

bash
npm init

This will ask you questions about your project and create package.json based on your answers.

Quick setup with defaults:

bash
npm init -y

The -y flag skips all questions and creates package.json with default values.

4Verify the clone is complete (for cloned repositories)

If you cloned a repository from Git but still get ENOPROJECT, the clone may be incomplete.

bash
# Check if package.json exists
ls package.json

# If missing, try cloning again
cd ..
rm -rf project-name
git clone https://github.com/user/repo.git
cd repo
ls -la

On Windows, use dir instead of ls, and use rmdir /s instead of rm -rf.

Advanced notes

In Docker environments, ensure your working directory is set correctly in the Dockerfile with the WORKDIR instruction and that package.json is included in the build context. In CI/CD pipelines, verify that the build step runs in the correct working directory before npm install. If using npm workspaces, ensure you're running commands from the root workspace directory.

Frequently asked questions

What does "npm ERR! code ENOPROJECT npm ERR! Not a project directory (no package." mean?
json file present. js project and tells npm what your project is, what dependencies it has, and what scripts can be executed. When npm looks for this file in your current directory and doesn't find it, it treats the location as not a valid project directory.
How do I fix "npm ERR! code ENOPROJECT npm ERR! Not a project directory (no package."?
This error occurs when npm commands are run in a directory without a package.json file. It means you're in the wrong directory or haven't initialized your Node.js project yet.
What causes "npm ERR! code ENOPROJECT npm ERR! Not a project directory (no package."?
Current working directory is not the project root (you're in a subdirectory or parent folder) The package.json file was accidentally deleted or never created Repository clone was incomplete or corrupted, missing the package.json file
Is the "npm ERR! code ENOPROJECT npm ERR! Not a project directory (no package." error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading