How to fix npm ERR! code ENOPACKAGEJSON in npm

npmBEGINNERMEDIUMUpdated Dec 6, 2025ยท 203 views

The ENOPACKAGEJSON error occurs when npm cannot find a package.json file in the expected location. This usually means you're in the wrong directory or haven't initialized your project.

Quick fix

Fixes npm ERR! code ENOPACKAGEJSON

pwd
ls -la package.json

# Find package.json in parent directories
find .. -maxdepth 3 -name "package.json"
  1. Check current directory
  2. Navigate to project root
  3. Initialize a new project
  4. Check file permissions
npm โ€” error
pwd
ls -la package.json
# Find package.json in parent directories
find .. -maxdepth 3 -name "package.json"
npm ERR! code ENOPACKAGEJSON

What this error means

This error indicates that npm couldn't find a package.json file when it expected one. Every npm project requires a package.json file in its root directory to define the project metadata, dependencies, and scripts. Without package.json, npm doesn't know what packages to install, what scripts are available, or even what the project is called.

Typical symptoms

  • npm install fails immediately
  • Error says no package.json found
  • New project not initialized
  • Running npm in wrong directory
  • package.json was deleted
  • File permissions issue

Common causes

  1. Not in project root directory
  2. Project not initialized with npm init
  3. package.json was accidentally deleted
  4. Case sensitivity issue (Package.json vs package.json)
  5. File permissions preventing read
  6. Symbolic link broken
  7. Working in subdirectory

How to fix "npm ERR! code ENOPACKAGEJSON"

1Check current directory

Verify you're in the right location:

bash
pwd
ls -la package.json

# Find package.json in parent directories
find .. -maxdepth 3 -name "package.json"
2Navigate to project root

Move to the correct directory:

bash
# Go to project root
cd /path/to/your/project

# Verify package.json exists
ls package.json
3Initialize a new project

If starting fresh:

bash
# Interactive init
npm init

# Quick init with defaults
npm init -y

This creates a basic package.json.

4Check file permissions

Ensure the file is readable:

bash
ls -la package.json

# Fix permissions if needed
chmod 644 package.json
5Restore from git

If package.json was deleted:

bash
# Check if it was tracked
git status

# Restore it
git checkout HEAD -- package.json
6Check for case sensitivity

On case-sensitive systems:

bash
# List all variations
ls -la [Pp]ackage.json

# Rename if wrong case
mv Package.json package.json

Advanced notes

Some npm commands can run without package.json (npm search, npm view), but most require it. When using monorepos with workspaces, ensure you're in the correct workspace directory. Docker builds often fail with this error if the COPY command didn't include package.json. CI/CD should verify package.json exists before running npm commands.

Frequently asked questions

What does "npm ERR! code ENOPACKAGEJSON" mean?
json file when it expected one. json file in its root directory to define the project metadata, dependencies, and scripts. json, npm doesn't know what packages to install, what scripts are available, or even what the project is called.
How do I fix "npm ERR! code ENOPACKAGEJSON"?
The ENOPACKAGEJSON error occurs when npm cannot find a package.json file in the expected location. This usually means you're in the wrong directory or haven't initialized your project.
What causes "npm ERR! code ENOPACKAGEJSON"?
Not in project root directory Project not initialized with npm init package.json was accidentally deleted
Is the "npm ERR! code ENOPACKAGEJSON" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading