Skip to content

Build from source

pkg has so-called base binaries — Node.js executables with some patches applied. They're used as the starting point for every executable pkg creates. By default pkg downloads pre-compiled base binaries from pkg-fetch before packaging your application.

If you prefer to compile base binaries from source, pass --build:

sh
pkg --build index.js

Slow

Compiling a full Node.js binary takes tens of minutes on a fast machine and can easily hit hours on slower hardware. Only use --build when you actually need a custom compile.

Prerequisites

Your machine needs everything Node.js requires to compile from source. The authoritative list is in nodejs/node/BUILDING.md. At a minimum:

  • A C/C++ toolchain (gcc, clang, or MSVC)
  • Python 3
  • GNU make or Ninja
  • Several GB of free disk and memory

When to build from source

  • Targeting an architecture not in pkg-fetch releases and not in pkg-binaries
  • Applying your own patches on top of pkg-fetch's patches
  • Debugging a pkg issue that requires a custom Node.js build

Otherwise, stick with the default — downloaded binaries are faster, cached, and covered by CI.

Future direction

SEA mode removes the need for patched Node.js binaries entirely. See SEA vs Standard and the pkg-fetch elimination roadmap. If you're reaching for --build because pkg-fetch doesn't cover your target, SEA may solve it upstream.

See also

Released under the MIT License.