Home·Error messages

npm · npm

The message

npm ERR! enoent ENOENT: no such file or directory, open '/home/me/package.json'

What it means

npm looked for package.json in the current directory and up the tree and found none — you ran an npm command somewhere that is not a project. It happens when you stand at the root of a monorepo while the project is in a subfolder, when you stand next to the folder you cloned, or when you simply forgot to cd. Moving to the folder that has package.json is the answer, and an ls is the quickest way to see it. Use npm init -y only if you genuinely mean to start a new project here: run in the wrong folder it leaves a stray package.json that confuses tooling later.

The fix

npm init -y
Printed by
npm
npm
20

With npm the cause sits in the first code XXXX line rather than the last six npm ERR! lines, and when the failure comes from the dependency tree or a native build instead of your own code, deleting node_modules and installing again clears about half of them.

Reading an error message

  • Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
  • If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
  • Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
  • The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
  • Before pasting a fix, check what it throws away. Some of these cannot be undone.

Common questions

Q. What does “npm ERR! enoent ENOENT: no such file or directory, open '/home/me/package.json'” mean?

npm looked for package.json in the current directory and up the tree and found none — you ran an npm command somewhere that is not a project. It happens when you stand at the root of a monorepo while the project is in a subfolder, when you stand next to the folder you cloned, or when you simply forgot to cd. Moving to the folder that has package.json is the answer, and an ls is the quickest way to see it. Use npm init -y only if you genuinely mean to start a new project here: run in the wrong folder it leaves a stray package.json that confuses tooling later.

Q. How do I fix it?

npm init -y — before running it, check the explanation above for what this command discards.

Q. Which tool prints this?

npm. It sits under npm, and the message runs to 11 words.

Errors nearby