How to solve npm ERR! enoent This is related to npm not being able to find a file

When running npm commands from the terminal, you may get an error with code ENOENT.

Here’s an example of the error message log when running the npm start command:

$ npm start

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /nsebhastian/Desktop/DEV/n-app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open 
'/nsebhastian/Desktop/DEV/n-app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

As you can see, there’s an error with code ENOENT that prevents npm start command from running successfully.

The code ENOENT means that npm fails to open a file or directory that’s required for executing the command.

The npm start command is used to run the start script in the package.json file.

When the package.json file isn’t found, then npm throws the ENOENT error.

To fix the error, you need to make sure that the file or directory needed for running the command is available.

In the case above, adding a package.json file to the project will solve the error.

If that doesn’t work, then you probably don’t have a start script in your package.json file.

Learn more here: How to fix npm start command not working

Also, make sure that you are running the command from the project directory, right where the package.json file is located.

npm commands don’t work when you run them from a parent or child directory.

npm install fails with code ENOENT

The ENOENT error may also appear when you run the npm install command.

Here’s an example of the error:

$ npm install

npm ERR! path /Users/nsebhastian/node_modules/sqlite3/node_modules/node-pre-gyp/node_modules/npmlog/node_modules/are-we-there-yet/node_modules/delegates
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 
'/Users/nsebhastian/node_modules/sqlite3/node_modules/node-pre-gyp/node_modules/npmlog/node_modules/are-we-there-yet/node_modules/delegates' -> '/Users/nsebhastian/node_modules/sqlite3/node_modules/node-pre-gyp/node_modules/npmlog/node_modules/are-we-there-yet/node_modules/.delegates.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

The error above happens because you have a dependency that doesn’t install correctly.

Here are the steps to resolve this issue:

  • Make sure you are using the latest npm version
  • Clean your npm cache
  • Delete node_modules folder and package-lock.json
  • Run npm install again

Run the following commands one by one from the terminal:

# 👇 update npm to the latest version
npm install -g npm@latest

# 👇 clean npm cache
npm cache clean --force

# 👇 delete node modules and package-lock.json 
npm rm -rf node_modules && rm package-lock.json

# 👇 retry installing dependencies
npm install

The npm install command should now run successfully.

And that’s how you solve the npm error code ENOENT: no such file or directory error.

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.