ENOENT: a file or folder your command expects is not there
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'Short answer
ENOENT means some part of the path in the message does not exist. The path is the clue. If it ends in package.json, you are in the wrong folder or the project has none. If it is your own file or folder, the code resolved a relative path against the wrong working directory, or the folder was never created.
Fix it fast
1Find out which cause you have
Copy the path from the message, then print the folder you are in and check what is there. Do this before changing anything.
pwd ls -la2Match what you see, then jump to its fix
- 1
ENOENT ... open '.../package.json'There is no package.json in the folder you ran npm inFix - 2
ENOENT on a path starting with ./ or a bare folder name, only when the app is started from a different folder, a service or a process managerA relative path is resolved against the working directoryFix - 3
ENOENT with mkdir or open on a path whose parent folder is missing, for example an uploads folder after a fresh deployThe folder was never created before a file or subfolder is written into itFix - 4
ENOENT lstat, ENOENT chmod or ENOTEMPTY unlink during npm install, often with several installs running at onceConcurrent installs hit missing files in an old npmFix
- 1
What does the error look like?
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'Error: ENOENT: no such file or directory, open './uploads/photo.png'Error: ENOENT: no such file or directory, mkdir
Cause 1 of 4
There is no package.json in the folder you ran npm in
1Check
npm reads the dependency list from package.json in the current project. A shell opened one level above or below the project, or a project that never had one, produces this message.
pwd
ls package.json2Fix
Change into the project folder. For a new project, create the file.
cd path/to/your-project
# or, for a new project:
npm init -y3Verify
npm now finds the project.
npm installConfirmed by docs.npmjs.com
Cause 2 of 4
A relative path is resolved against the working directory
1Check
A relative path is read from the directory the Node.js process started in, not from the file that contains the code. Print it and compare.
node -e "console.log(process.cwd())"2Fix
Build the path from the file's own location with __dirname, so the start folder no longer matters.
const path = require('node:path');
const uploads = path.join(__dirname, 'uploads');3Verify
Start the app from another folder and repeat the failing action.
cd / && node /path/to/your-project/server.jsConfirmed by nodejs.org
Cause 3 of 4
The folder was never created before a file or subfolder is written into it
1Check
Writing into a folder that does not exist fails with ENOENT. The folder may sit in .gitignore and so be absent on the server.
ls -ld uploads2Fix
Create the folder when the app starts. The recursive option creates missing parents too and does not fail if the folder already exists.
const fs = require('node:fs');
fs.mkdirSync(path.join(__dirname, 'uploads'), { recursive: true });3Verify
Restart the app and repeat the upload or write.
ls -ld uploadsConfirmed by nodejs.org
Cause 4 of 4
Concurrent installs hit missing files in an old npm
1Check
npm documents these as race conditions during concurrent installs. Check your npm version and make sure only one install runs.
npm --version
ps aux | grep "[n]pm install"2Fix
Update npm, remove the half-written node_modules and install again.
npm install -g npm@latest
rm -rf node_modules
npm install3Verify
The install completes without ENOENT lines.
npm ls --depth=0Confirmed by docs.npmjs.com
How do I stop it coming back?
- Build file paths from __dirname, never from a bare relative string.
- Create runtime folders in code, not by hand on the server.
- Run one npm install at a time per project, including in CI.
- Read the path in the message first: it names the exact thing that is missing.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Node.js cannot start the program it was asked to run
Error: spawn npm ENOENT
spawn ENOENT means the operating system could not start the file Node asked for.
5 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
firebase deploy stops because the predeploy lint step failed
Error: There was an error deploying functions
The predeploy hook in firebase.json runs npm run lint before every deploy, and a failing hook cancels the deploy.
3 causes, each with a fix