Node.js

Fix node-gyp build errors during npm install

Some packages build a small piece of C++ when they install. The fix is almost always to install the build tools and Python, then reinstall.

  1. Install the build tools
    Terminal
    xcode-select --install

    A window pops up. Click Install. Already installed? It says so and you can move on.

  2. Update npm, which brings a newer node-gyp
    Terminal
    npm install -g npm@latest

    This fixes "No module named distutils", which older node-gyp versions hit with newer Python.

  3. Reinstall the project's packages
    Terminal
    rm -rf node_modules && npm install

Check it worked

  1. Check node-gyp can find what it needs
    Terminal
    npx node-gyp --version && python3 --version && clang --version
  1. Install the build tools and PythonNeeds sudo
    Terminal · Ubuntu / Debian
    sudo apt install -y build-essential python3

    On Fedora: sudo dnf group install development-tools, then sudo dnf install python3.

  2. Update npm, which brings a newer node-gyp
    Terminal · Ubuntu / Debian
    npm install -g npm@latest

    This fixes "No module named distutils", which older node-gyp versions hit with newer Python.

  3. Reinstall the project's packages
    Terminal · Ubuntu / Debian
    rm -rf node_modules && npm install

Check it worked

  1. Check node-gyp can find what it needs
    Terminal · Ubuntu / Debian
    npx node-gyp --version && python3 --version && gcc --version
  1. Install the Visual Studio C++ build tools
    PowerShell
    winget install Microsoft.VisualStudio.2022.BuildTools --override "--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"

    About 5 GB. This is what "gyp ERR! find VS" is asking for.

  2. Install Python
    PowerShell
    winget install Python.Python.3.12

    Close and reopen PowerShell afterwards so it can find Python.

  3. Update npm, which brings a newer node-gyp
    PowerShell
    npm install -g npm@latest
  4. Reinstall the project's packages
    PowerShell
    Remove-Item -Recurse -Force node_modules; npm install

Check it worked

  1. Check node-gyp can find what it needs
    PowerShell
    npx node-gyp --version; python --version