Home·Error messages

node-gyp · npm

The message

gyp ERR! build error

What it means

A dependency contains C or C++ that has to be compiled on your machine at install time, and that compile failed — node-gyp needs a compiler and python. It happens when no build toolchain is installed, or when the package is older than your node and the headers no longer match. Install the toolchain: xcode-select --install for the command line tools on macOS, build-essential and python3 on Debian or Ubuntu, the Visual Studio C++ workload on Windows. If a newer version of the package ships a prebuilt binary for your node, upgrading the package is far quicker than fixing the build environment.

The fix

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

Printed by
node-gyp
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 “gyp ERR! build error” mean?

A dependency contains C or C++ that has to be compiled on your machine at install time, and that compile failed — node-gyp needs a compiler and python. It happens when no build toolchain is installed, or when the package is older than your node and the headers no longer match. Install the toolchain: xcode-select --install for the command line tools on macOS, build-essential and python3 on Debian or Ubuntu, the Visual Studio C++ workload on Windows. If a newer version of the package ships a prebuilt binary for your node, upgrading the package is far quicker than fixing the build environment.

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?

node-gyp. It sits under npm, and the message runs to 4 words.

Errors nearby