Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

ENOENT: a file or folder your command expects is not there

Errornpm 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.

  • Applies to npm 10, Node.js 22, Ubuntu 24.04, macOS 15, Windows 11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 -la
  2. 2Match what you see, then jump to its fix

    1. 1ENOENT ... open '.../package.json'There is no package.json in the folder you ran npm inFix
    2. 2ENOENT 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. 3ENOENT 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. 4ENOENT lstat, ENOENT chmod or ENOTEMPTY unlink during npm install, often with several installs running at onceConcurrent installs hit missing files in an old npmFix

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.json

2Fix

Change into the project folder. For a new project, create the file.

cd path/to/your-project
# or, for a new project:
npm init -y

3Verify

npm now finds the project.

npm install

Confirmed by docs.npmjs.com

Did this fix it?

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.js

Confirmed by nodejs.org

Did this fix it?

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 uploads

2Fix

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 uploads

Confirmed by nodejs.org

Did this fix it?

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 install

3Verify

The install completes without ENOENT lines.

npm ls --depth=0

Confirmed by docs.npmjs.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.