Photo by Bernd ๐ท Dittrich on Unsplash
So there I was, cloning a repo a teammate had sent over, running npm install like I've done a thousand times, and immediately getting slapped with this error before the terminal even blinked:
npm warn saveError ENOENT: no such file or directory, open '/home/user/myproject/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/myproject/package.json'
npm warn myproject No description
npm warn myproject No repository field.
npm warn myproject No README data
npm warn myproject No license field.
Classic. The package.json not found error during npm install is one of those things that sounds way scarier than it usually is — but it can also mean a few different things depending on your setup, so let me walk you through what actually causes this and how to get unstuck.
Why This Happens in the First Place
npm looks for a package.json file in whatever directory you're currently sitting in when you run the install command. No package.json? It panics. Simple as that.
The reasons this comes up are almost always one of three things: you're in the wrong directory, the file genuinely doesn't exist yet (maybe it's a brand new project), or something went wrong when the repo was cloned and the file didn't come through. I've also seen this happen when someone accidentally .gitignore'd their package.json, which — look, it happens, no judgment.
Fix #1: You're Just in the Wrong Folder (Most Common)
Honestly, this is the answer 80% of the time. Before anything else, check where you actually are:
pwd
Then list out the files in that directory:
ls -la
If you don't see a package.json in that output, you need to navigate into the right folder. A lot of repos have the actual Node project nested inside a subdirectory — something like /client or /app or /frontend. I've seen this trip up even senior devs who are moving fast.
cd client
npm install
That's it. That's the whole fix. Go get yourself a coffee, you're done.
Fix #2: You Need to Initialize a New package.json
If you're starting fresh — like spinning up a brand new Node or React project — there's no package.json yet because you haven't created one. npm isn't going to magically conjure it for you.
Run this in your project root:
npm init -y
The -y flag just says "yes to everything" and generates a default package.json without making you answer a bunch of questions. You can always go in and edit the name, version, description, and all that stuff afterward. Once that file exists, your npm install commands will work fine.
Now here's where it gets tricky — if you're working with a framework like Next.js, Vite, or Create React App, you typically shouldn't be running npm init manually. Those tools scaffold the whole project structure for you, including the package.json. If you're missing it, something went wrong during scaffolding and you might want to just re-run the create command.
# Example — scaffold a fresh Vite project
npm create vite@latest my-app
cd my-app
npm install
Fix #3: The File Was Lost During Cloning
This one's a bit more annoying to diagnose. If you cloned a repo and the package.json is genuinely missing, it might not have been committed to the repository in the first place. Check the remote repo on GitHub or GitLab directly — can you see a package.json at the root? If yes, try deleting your local copy and re-cloning cleanly:
git clone https://github.com/username/repo-name.git
cd repo-name
ls
If the file shows up on the remote but not locally, something went sideways with your clone. Re-cloning almost always fixes it. If the file isn't on the remote either, you need to talk to whoever owns the repo — they probably forgot to commit it.
(Side note: I once spent 45 minutes debugging this exact situation, only to realize the repo owner had added package.json to their .gitignore by mistake. We've all been there.)
Fallback Tip: Specify the Path Directly
If for whatever reason you're running npm commands from a different working directory — maybe in a CI/CD pipeline or a script — you can point npm at the right prefix path explicitly:
npm install --prefix ./path/to/your/project
This tells npm exactly where to look for the package.json rather than defaulting to wherever the shell currently is. Super useful in automated environments where you don't always control the current working directory. I lean on this a lot in Docker build scripts where paths get weird fast.
Quick Sanity Checklist
If you're still stuck after all that, run through these real quick before you go any further:
- Are you in the actual project root? (
pwdandlsare your friends) - Does the
package.jsonexist on the remote repository? - Is
package.jsonlisted in your.gitignoreby accident? - Are you using the right Node and npm versions? (Sometimes version mismatches cause weird pathing behavior — check with
node -vandnpm -v)
In my experience, the "wrong directory" fix covers the vast majority of cases. It's one of those errors where the message sounds technical but the root cause is almost embarrassingly simple. Don't overthink it — check your path first, every time.
Hope this saves you from staring at your terminal for longer than necessary.
Related: How to Fix npm Error Code ENOENT (And Actually Understand Why It Happens)
๋๊ธ
๋๊ธ ์ฐ๊ธฐ