Resolve npm WARN saveError ENOENT no such file or directory message

When running the npm install command, you might see a warning that says saveError ENOENT on the console.

The warning message looks as follows:

$ npm install react
npm WARN saveError ENOENT: no such file or directory, 
open '/Users/nsebhastian/DEV/n-app/package.json'
npm WARN enoent ENOENT: no such file or directory, 
open '/Users/nsebhastian/DEV/n-app/package.json'

+ [email protected]
added 3 packages from 2 contributors and audited 3 packages in 1.536s
found 0 vulnerabilities

As you can see, there’s a warning with the code ENOENT in the console above.

The first thing to note is that a warning message doesn’t affect the installation of the package. You can import and use the package you have installed just fine.

Now let’s learn what the message means. The ENOENT code means Error NO ENTity or Error NO ENTry, and the cause of this message is that npm can’t find the file or directory it wants to access.

The npm install command causes npm to seek the package.json file. It wants to add the packages you installed as dependencies of the project.

To resolve the ENOENT warning message, you need to add a package.json file in the directory where you run the npm install command.

Run the following command to create your package.json file:

npm init -y

And then run your npm install command again. This time, the warning message should not appear.

Alternatively, you can just update npm to the latest version to remove the warning message.

In the latest npm version, the npm install command will generate a package.json file when it can’t find one in your working directory.

Learn how to update npm.

Now you’ve learned how to resolve the npm saveError ENOENT warning message. Nice work! 👍

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.