- Instant help with your JavaScript coding problems

Fix npm ERR! enoent ENOENT: no such file or directory error

A common problem with Node.js projects is that a given npm command returns the following error:

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Mike\project\package.json'

 

What causes the error

Luckily, the error message will tell you exactly what it can't find. The npm output is usually more verbose, but it is easy to find the critical file:

npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path C:\Users\Mike\project\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\Mike\project\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Mike\AppData\Local\npm-cache\_logs\2023-07-14T05_51_46_208Z-debug-0.log

All you have to do is follow the path provided and check if the file actually exists. It is possible that the file exists but cannot be read because you do not have the right permission to it or it is corrupted for some reason. 

Fix the error

Depending on why the package.json file is not available, you can solve the problem by following the steps below:

The file package.json doesn't exists:

Create the file using the command npm init  

The file is not readable:

Change user permission on the file

The file is corrupted:

Create a backup from the file and remove the original and recreate it using npm init .

Variations

Although in most cases it is the package.json file that is affected, there are times when the error occurs, for example, when running an npx command:

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Mike\AppData\Roaming\npm'

In this case, npm is not available due to a configuration or installation problem. In this case, reinstalling npm or npx can help:

npm i -g npm or npm i -g npx

 

Share "Fix npm ERR! enoent ENOENT: no such file or directory error" with your friends