Photo by Fotis Fotopoulos on Unsplash
So there I was, cloning a repo at 11pm trying to get a project running before a demo the next morning, and I get hit with this beauty:
npm warn saveError ENOENT: no such file or directory, open '/home/user/projects/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/user/projects/package.json'
npm WARN projects No description
npm WARN projects No repository field.
npm WARN projects No README data
npm WARN projects No license field.
Honestly, this is one of those errors that looks scarier than it is. The good news: nine times out of ten, there's a dead simple fix. The annoying news: there are a few different reasons this can happen, so you have to figure out which one you're dealing with.
Let me walk you through what's actually going on and how to get past it.
Why This Error Happens
When you run npm install, npm immediately looks for a package.json file in whatever directory your terminal is currently sitting in. That's it. No package.json? It panics and throws that ENOENT error. ENOENT, by the way, just means "Error NO ENTry" — basically the OS saying "I looked everywhere, this file doesn't exist here."
The causes usually fall into one of three buckets:
1. You're in the wrong directory. This is the most common one, and I've seen it trip up developers with years of experience. You cloned the repo, your terminal is still sitting in the parent folder, and you just ran npm install without cd-ing into the actual project folder first.
2. The package.json file genuinely doesn't exist yet. Maybe you're starting a brand new project from scratch and skipped the npm init step. Or someone handed you a folder with just source files and no manifest.
3. The file got corrupted or accidentally deleted. Less common, but it happens — especially if you've been messing around with git resets, manual file deletions, or a botched merge.
Fix #1 — Just Navigate Into the Right Folder (Seriously, Check This First)
Before you do anything else, run this:
ls
Or on Windows:
dir
Look at what's in your current directory. Do you see a package.json file listed? If not, you're probably one level up from where you need to be. If you cloned a repo called my-app, you need to do this:
cd my-app
npm install
I can't tell you how many Stack Overflow threads are just... this. Someone forgot to cd into the project. No shame in it — I've done it myself after a long day when my brain was running on fumes.
Fix #2 — Initialize a Fresh package.json
If you're starting a new project and there's genuinely no package.json yet, you need to create one first. You've got two options here.
The interactive way, which walks you through naming your project, setting the version, entry point, etc.:
npm init
Or if you just want to skip all the questions and get a default package.json generated instantly:
npm init -y
The -y flag just says "yes to everything, give me the defaults." After that runs, you'll have a shiny new package.json sitting in your directory and you can run npm install <package-name> to start adding dependencies.
Honestly, for quick projects or testing stuff, npm init -y is almost always what I reach for. I'll clean up the metadata later.
Fix #3 — Recover a Missing or Corrupted package.json from Git
Now here's where it gets a little more interesting. If you know the file existed before and something went sideways — a bad merge, an accidental delete, whatever — you can pull it back from git history.
First, check if git even knows about it:
git log --oneline --all -- package.json
If you see commits listed, the file was there at some point. You can restore it from the last known good commit like this:
git checkout HEAD -- package.json
Or if you need to grab it from a specific commit (use the hash from the log output above):
git checkout abc1234 -- package.json
After that, run npm install again and you should be good. If the node_modules folder is also missing at this point (which it probably is), that's fine — npm install will rebuild it from scratch using whatever's in your package.json.
Side note: if you're on a team project and someone else has the repo set up correctly, you can also just ask them to send you a copy of their package.json. Low-tech, but it works.
Fallback Tip — Double-Check Your Node and npm Versions
This is a weird edge case but worth mentioning. Very occasionally, this error shows up because of a permissions issue or a seriously outdated npm version doing something unexpected. Before you go down a rabbit hole, just verify your environment is sane:
node -v
npm -v
If your npm version is ancient (anything below version 6 in 2024 is a red flag), update it:
npm install -g npm@latest
And if you're managing multiple Node versions across projects — which, if you aren't already doing, you really should look into — tools like nvm (Node Version Manager) can save you a lot of headaches. But that's a whole other conversation.
The npm install package.json not found error sounds intimidating the first time you see it, but it almost always boils down to being in the wrong folder or missing an init step. Start with Fix #1, and you'll solve it in about 10 seconds. Hope this saves you the 45 minutes of Googling I went through the first time I hit it.
Related: How to Fix npm Error Code ENOENT (And Why It Keeps Happening)
๋๊ธ
๋๊ธ ์ฐ๊ธฐ