How to fix Error: Could not find package.json in current directory (npm module resolution) in Node.js

Node.jsBEGINNERMEDIUMUpdated Dec 8, 2025ยท 626 views

This error occurs when npm or Node.js cannot locate a package.json file in the directory where you are running commands. The package.json file is required for dependency management and project configuration.

Quick fix

Fixes Error: Could not find package.json in current directory (npm module resolution)

# Check current directory
pwd

# List files to see if package.json exists
ls -la
# On Windows:
dir

# If package.json is not in current directory, find it
find . -name "package.json" -type f
# On Windows:
where /r . package.json
  1. Verify you are in the correct directory
  2. Initialize a new package.json if it is missing
  3. Fix deployment and build configurations
  4. Check version control and restore package.json
node.js โ€” error
# Check current directory
pwd
# List files to see if package.json exists
ls -la
# On Windows:
dir
# If package.json is not in current directory, find it
find . -name "package.json" -type f
# On Windows:
where /r . package.json
Error: Could not find package.json in current directory (npm module resolution)

What this error means

This error indicates that npm, Node.js, or a build tool is attempting to read the package.json file but cannot find it in the current working directory or in the expected location. The package.json file is the manifest that defines a Node.js project, including its dependencies, scripts, metadata, and configuration. Node.js module resolution follows a specific algorithm that searches for package.json files starting from the current directory and traversing up the directory tree. When npm commands like npm install, npm start, or npm run are executed, they expect to find a package.json in the current directory or in parent directories. If the file is missing, in a subdirectory, or the command is run from the wrong location, this error occurs. This can also happen during deployment pipelines, containerized builds, or when working with monorepos where multiple package.json files exist at different levels. Understanding where Node.js expects to find this file is critical for troubleshooting.

Typical symptoms

  • Error message "npm can't find a package.json file in your current directory"
  • Error "Could not find package.json" when running npm install or npm commands
  • Build scripts fail with "Cannot find module package.json"
  • Deployment pipelines fail at the npm install step
  • Warning "Local package.json exists, but node_modules missing"
  • npm commands return ENOENT error referencing package.json
  • Module resolution fails in nested project structures
  • Docker builds fail during npm install phase

Common causes

  1. Running npm commands from a directory that does not contain package.json
  2. package.json file is located in a subfolder instead of the project root
  3. Incorrect working directory set in deployment configuration or CI/CD pipeline
  4. package.json file was accidentally deleted or not committed to version control
  5. Permissions issues preventing read access to package.json
  6. File system case sensitivity issues (package.json vs Package.json)
  7. Working in a parent directory when package.json is in a child directory
  8. Monorepo structure where build commands start from wrong directory level

How to fix "Error: Could not find package.json in current directory (npm module resolution)"

1Verify you are in the correct directory

First, check your current working directory and confirm package.json exists:

bash
# Check current directory
pwd

# List files to see if package.json exists
ls -la
# On Windows:
dir

# If package.json is not in current directory, find it
find . -name "package.json" -type f
# On Windows:
where /r . package.json

If you find package.json in a subdirectory, navigate to it:

bash
cd path/to/directory/with/package-json
npm install
2Initialize a new package.json if it is missing

If package.json does not exist in your project, create one:

bash
# Interactive initialization (prompts for project details)
npm init

# Quick initialization with defaults
npm init -y

# This creates a basic package.json:
{
  "name": "my-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

After creating package.json, install your dependencies:

bash
npm install express mongoose dotenv
3Fix deployment and build configurations

If this error occurs during deployment or CI/CD, adjust the working directory:

GitHub Actions:

yaml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        working-directory: ./backend  # Set correct directory
        run: npm install

Docker:

dockerfile
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .

Render/Heroku/Platform config:
Set the root directory or build command path in your platform's settings:

bash
# If package.json is in a subfolder
cd backend && npm install && npm start
4Check version control and restore package.json

If package.json was accidentally deleted or not committed:

bash
# Check if package.json is in .gitignore (it should NOT be)
cat .gitignore | grep package.json

# If package.json was deleted, restore from git
git checkout HEAD -- package.json

# Or restore from a specific commit
git show <commit-hash>:package.json > package.json

# If you committed code without package.json, create one
npm init -y
# Then reinstall dependencies based on your imports:
npm install <package-names>

Always commit package.json and package-lock.json to version control.

5Verify file permissions and case sensitivity

Check that Node.js can read the package.json file:

bash
# Check file permissions (should be readable)
ls -l package.json
# Output should show read permissions: -rw-r--r--

# Fix permissions if needed
chmod 644 package.json

# Check for case sensitivity issues
# Ensure the file is named exactly "package.json" (lowercase)
ls -la | grep -i package.json

# Rename if necessary
mv Package.json package.json

On Windows, file system is case-insensitive, but in Linux/macOS or containers it is case-sensitive.

6Handle monorepo and workspace structures

For monorepos with multiple package.json files, ensure commands run from the correct workspace:

Using npm workspaces:

json
// Root package.json
{
  "name": "my-monorepo",
  "workspaces": [
    "packages/*"
  ]
}

Run commands for specific workspaces:

bash
# Install all workspace dependencies from root
npm install

# Run command in specific workspace
npm run build --workspace=packages/backend

# Or navigate to the workspace
cd packages/backend
npm run build

For pnpm or yarn workspaces, use their workspace commands accordingly.

7Debug npm link and local dependency issues

If using npm link or developing packages locally:

bash
# Check for duplicate or mislinked packages
npm ls

# If you see errors about missing package.json in linked packages
cd /path/to/your/linked/package
npm link

# Then in your main project
cd /path/to/main/project
npm link package-name

# For module resolution conflicts, clear cache
npm cache clean --force
rm -rf node_modules package-lock.json
npm install

Ensure linked packages have valid package.json files with proper main or exports fields.

Advanced notes

Node.js module resolution algorithm searches for package.json files by traversing up the directory tree from the module's location. For packages, it checks node_modules at each level until it reaches the root of the file system. When Node.js cannot find package.json, it typically means the search algorithm exhausted all parent directories without finding the file.

In monorepo setups, there have been proposals to add a mechanism to stop module resolution at a specific directory boundary (GitHub issue nodejs/node#43368), but currently the search always goes to the file system root. This can cause unexpected behavior when multiple package.json files exist at different tree levels.

The package.json main field and newer exports field control entry point resolution. If a package.json exists but lacks these fields, Node.js may report "Cannot find package" even though the file exists. The exports field provides more control over which files are exposed:

json
{
  "name": "my-package",
  "exports": {
    ".": "./dist/index.js",
    "./utils": "./dist/utils.js"
  }
}

For TypeScript projects, ensure tsconfig.json and package.json are in sync regarding module resolution. TypeScript's moduleResolution setting (node, node16, bundler) affects how it finds type definitions and correlates with npm's runtime resolution.

In containerized environments, common mistakes include incorrect WORKDIR settings or COPY commands that don't include package.json before running npm install. Always copy dependency manifests first to leverage Docker layer caching:

dockerfile
COPY package*.json ./
RUN npm ci --only=production
COPY . .

Frequently asked questions

What does "Error: Could not find package.json in current directory (npm module re" mean?
json file but cannot find it in the current working directory or in the expected location. js project, including its dependencies, scripts, metadata, and configuration. json files starting from the current directory and traversing up the directory tree.
How do I fix "Error: Could not find package.json in current directory (npm module re"?
This error occurs when npm or Node.js cannot locate a package.json file in the directory where you are running commands. The package.json file is required for dependency management and project configuration.
What causes "Error: Could not find package.json in current directory (npm module re"?
Running npm commands from a directory that does not contain package.json package.json file is located in a subfolder instead of the project root Incorrect working directory set in deployment configuration or CI/CD pipeline
Is the "Error: Could not find package.json in current directory (npm module re" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading