How to fix: “npm ERR! code ENOENT … Could not read package.json”

How to fix: “npm ERR! code ENOENT … Could not read package.json”

This is one of those bugs that will send you down the rabbit hole.

The short version: ENOENT is the system’s way of saying “can’t find what you asked for.” In Node/npm land, it most often means the file or folder doesn’t exist at the path npm expects. When you see:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\dropletdrift\Downloads\deploy site\package.json
npm ERR! errno -4058
npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open 'C:\Users\dropletdrift\Downloads\deploy site\package.json'

npm tried to open package.json in your current directory and Windows replied “no such file.” On Windows, the numeric errno often shows up as a negative number (like -4058), which maps to a system error code; Node normalizes these under the ENOENT label.

I’ve hit this many times. The fix ranges from “you’re in the wrong folder” to “the project doesn’t even have a package.json yet.” Below is how I work through it, quickly, and what to do when it’s not the obvious thing.

Confirm you’re in the right folder

Nine times out of ten, I simply wasn’t in the project root. The fix is to change into the folder that actually contains package.json, then run your npm command again.

On Windows PowerShell:

cd "C:\Users\dropletdrift\Downloads\deploy site"
dir

If package.json does not show in the listing, you’re not in the right place, or the project hasn’t been initialized yet. This “wrong directory” cause is the most common, and it matches npm’s own explanation that the error shows up when npm “can’t find the file it needs.”

Tip: paths with spaces are fine; just wrap them in quotes as above. If you often work in folders like “deploy site,” keep quoting in mind when you cd or when you write scripts that reference those paths.

If there’s no package.json, create one

New or copied folders won’t have a package.json until you initialize them. From the intended project folder:

npm init -y

This creates a minimal, valid package.json you can edit later. npm documents npm init as the standard way to bootstrap package.json.

After that, install your dependencies again:

npm install

If package.json exists but you still get ENOENT

At this point, I check for a few “gotchas” that are easy to miss on Windows.

Verify the working directory npm is using

Sometimes terminals open in a parent folder. Print the working directory and list files:

cd
pwd
dir

Confirm you see this project’s package.json and not one from somewhere else.

Watch for path quirks on Windows

Spaces are okay if quoted, but “roaming” profile paths, synced folders (like OneDrive/Dropbox), or restricted directories sometimes cause odd failures. If the project lives in a synced or protected folder, try moving it to a simpler path like C:\dev\myapp and retry. A lot of real-world threads about ENOENT end with “moved it out of OneDrive / a weird path and it worked.”

Clean up a stale or corrupted install state

If the directory is correct and package.json is present, your install state might be stale or partially corrupted. What I do:

rd /s /q node_modules
del package-lock.json
npm cache verify
npm install
  • npm cache verify is the supported way to sanity-check npm’s cache on modern npm. If you must force-clear, npm cache clean --force still exists, but verify is the first stop.

If this recovers your project, great. If not, keep going.

Run npm’s built-in health check

I like to run:

npm doctor

It checks your npm installation and common system prerequisites and can surface environment problems.

If npm doctor flags anything, fix it and re-run your original command.

Double-check Node and npm versions, then upgrade if needed

Old or mismatched Node/npm versions can lead to flaky install behavior, especially on Windows. I confirm versions:

node -v
npm -v

If they’re dated, install the latest LTS release of Node.js (which includes npm), then retry. Node’s error docs also explain that Windows error numbers get normalized by Node, which is why you see -4058 mapped to ENOENT; upgrading keeps you on a well-tested libuv/error stack.

I’ve fixed stubborn ENOENTs before simply by upgrading Node, nuking node_modules, and reinstalling.

When it’s not package.json at all

Occasionally the ENOENT isn’t about package.json but another path referenced by a script or tool you’re running through npm (for example, an asset path in angular.json, or a spawned executable in an npm run script). In those cases:

  • Read the stack trace to find which file can’t be found.
  • Fix the bad path in your config (e.g., angular.json, webpack config, a script in package.json), then re-run. This is a common cause of ENOENT in front-end pipelines.

If your script spawns other processes, note that spawn ENOENT means the executable couldn’t be found on PATH or under the given name; on Windows you may need to reference the .cmd/.bat wrapper or ensure the tool is installed and resolvable.

Why this happens so often (and how to avoid it next time)

I keep these habits and almost never see the error anymore:

  • Always open a terminal from the project root. In VS Code, use “Open in Integrated Terminal” from the folder root so the shell starts in the right place.
  • Keep projects out of sync folders if you can. Prefer C:\dev\project to Downloads, Desktop, or OneDrive.
  • Initialize first, install second. Run npm init -y (or your framework’s initializer) before npm install. npm’s own docs treat npm init as the canonical way to create a valid package.json.
  • When in doubt, verify cache and doctor the environment rather than blindly clearing caches or reinstalling. Modern npm is “self-healing,” and npm cache verify is the documented first step.

What ENOENT literally stands for

If you’re curious: ENOENT is short for “Error NO ENTry / Error NO ENTity.” It’s a long-standing POSIX-style error code that Node surfaces for missing files or directories. On Windows, Node maps system error numbers (like -4058) to these standard codes so they’re consistent across platforms.

mindmap
  root((ENOENT))
    Meaning:::concept
      "No such file or directory"
      "Standardized error code"
    Common npm causes:::causes
      "Wrong working directory"
      "No package.json yet"
      "Bad path in config/script"
      "Corrupted install state"
    Windows specifics:::windows
      "Quoted paths with spaces"
      "Synced/protected folders"
      "Error numbers normalized"

Was this helpful?

Thanks for your feedback!

Leave a comment

Your email address will not be published. Required fields are marked *