Home·Error messages

npm 6 · npm

The message

npm WARN react-dom@17.0.2 requires a peer of react@17.0.2 but none is installed.

What it means

npm 6 only warned about peer dependencies and never installed them for you: the package is present, but the companion it says it needs is not. It appears in a project still on npm 6, or when you are using an old lockfile made in that era. Install the named peer yourself at a version inside the printed range and it is done. Nothing has failed yet because this is only a warning, but it comes back later as Cannot find module, or as two copies of the same library producing errors that make no sense.

The fix

There is no one-line command for this. The explanation says what to look at instead.

Printed by
npm 6
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 WARN react-dom@17.0.2 requires a peer of react@17.0.2 but none is installed.” mean?

npm 6 only warned about peer dependencies and never installed them for you: the package is present, but the companion it says it needs is not. It appears in a project still on npm 6, or when you are using an old lockfile made in that era. Install the named peer yourself at a version inside the printed range and it is done. Nothing has failed yet because this is only a warning, but it comes back later as Cannot find module, or as two copies of the same library producing errors that make no sense.

Q. How do I fix it?

There is no one-line command. The explanation above says what to look at instead.

Q. Which tool prints this?

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

Errors nearby