Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Installing the sqlite3 package fails, or it installs without its binary

Your error

prebuild-install -r napi || node-gyp rebuild2 more lines it can show

Fix it fast

Most common cause, 1 of 3

No prebuilt binary exists for this platform, and no compiler is installed

Install the build tools node-gyp lists for your system, then force a source build.

Fix
# Ubuntu or Debian
sudo apt-get install -y python3 make g++
# macOS
xcode-select --install

npm install sqlite3 --build-from-source
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

npm install sqlite3 fails when its install script, prebuild-install -r napi || node-gyp rebuild, finds no prebuilt binary for the platform or cannot reach GitHub Releases, and the node-gyp fallback has no compiler. On npm 12 the script is skipped until allowScripts approves it. sqlite3 6 needs Node.js 20.17 or newer; node:sqlite needs no native build.

  • Applies to sqlite3 6.0.1, Node.js 22, Node.js 24, Node.js 26, npm 11, npm 12.2, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the Node.js version, the platform, the CPU and the npm version, then reinstall with the install script running in the foreground so its own output appears. Platform plus CPU tells you whether a prebuilt binary exists, the npm major tells you whether the script may run at all, and the output shows whether the download or the build broke.

Run this first
node -p "process.version + ' ' + process.platform + '-' + process.arch" && npm -v
npm install sqlite3 --foreground-scripts

Then find the line you see in this list and open its fix:

  1. 1No prebuilt binary exists for this platform, and no compiler is installedThe machine is not one of darwin-arm64, darwin-x64, linux-arm64, linux-x64, linuxmusl-arm64, linuxmusl-x64 or win32-x64, for example a 32-bit ARM board
  2. 2The prebuilt binary could not be downloadedThe platform is supported, yet the log shows the download step failing and node-gyp starting after it, often on CI runners or behind a company proxy
  3. 3npm 12 skipped the sqlite3 install scriptnpm -v prints 12.x, the install reports no error, and the end of its output lists packages whose install scripts were skipped

What does the error look like?

  • prebuild-install -r napi || node-gyp rebuild
  • npm install sqlite3 stops inside the install script of sqlite3
  • npm install finishes, but require('sqlite3') fails because the native binary was never fetched or built

Cause 1 of 3

No prebuilt binary exists for this platform, and no compiler is installed

You seeThe machine is not one of darwin-arm64, darwin-x64, linux-arm64, linux-x64, linuxmusl-arm64, linuxmusl-x64 or win32-x64, for example a 32-bit ARM board

Check

npm install sqlite3 fails on such a machine because no prebuilt binary exists for its platform and node-gyp then finds no compiler. Prebuilt binaries ship only for macOS and Linux (glibc or musl) on x64 or arm64, and for Windows x64; anywhere else the script falls through to node-gyp, which needs Python, make and a C/C++ compiler on Linux, or the Xcode Command Line Tools on macOS.

Check
node -p "process.platform + '-' + process.arch"

Fix

Install the build tools node-gyp lists for your system, then force a source build.

Fix
# Ubuntu or Debian
sudo apt-get install -y python3 make g++
# macOS
xcode-select --install

npm install sqlite3 --build-from-source

Verify

Open an in-memory database and print the SQLite version.

Verify
node -e "const sqlite3 = require('sqlite3'); const db = new sqlite3.Database(':memory:'); db.each('SELECT sqlite_version() AS v', (err, row) => console.log(err || row.v)); db.close();"

Confirmed by github.com

Did this fix it?

Cause 2 of 3

The prebuilt binary could not be downloaded

You seeThe platform is supported, yet the log shows the download step failing and node-gyp starting after it, often on CI runners or behind a company proxy

Check

npm install sqlite3 fails on a supported platform when the prebuilt download is blocked and the fallback build has no compiler. The binaries sit on GitHub Releases of the sqlite3 repository. A machine with no route to github.com never gets them; the install script then hands over to node-gyp, and on a runner with no compiler that step breaks too.

Check
curl -sSI https://github.com/TryGhost/node-sqlite3/releases | head -n 1

Fix

Let the runner reach GitHub Releases. Where that is not allowed, add Python, make and a C++ compiler to the image so the fallback build can succeed.

Fix
npm install sqlite3 --build-from-source

Verify

Run the install again on the same runner; it finishes and npm ls lists sqlite3.

Verify
npm ls sqlite3

Confirmed by github.com

Did this fix it?

Cause 3 of 3

npm 12 skipped the sqlite3 install script

You seenpm -v prints 12.x, the install reports no error, and the end of its output lists packages whose install scripts were skipped

Check

sqlite3 installs without its binary on npm 12 because npm skipped the package's install script. Since npm 12, dependency install scripts are blocked unless the allowScripts field in your package.json approves them. Without the script, sqlite3 never downloads or builds its binary.

Check
npm install-scripts ls

Fix

Approve sqlite3 after you have read its install script, then rebuild it so the approved script runs.

Fix
npm install-scripts approve sqlite3
npm rebuild

Verify

package.json now has a sqlite3 entry under allowScripts, and the in-memory version check prints a version.

Verify
grep -A3 allowScripts package.json

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Stay on Node.js 20.17.0 or newer, the range sqlite3 6 declares in its engines field, and use the same version on laptops, CI and servers.
  • Commit the allowScripts entries npm 12 writes, so every machine runs the same approved install scripts.
  • The sqlite3 README now marks the package deprecated and unmaintained. For new code, node:sqlite is built into Node.js (no flag needed since 22.13 and 23.4, release candidate since 24.15) and needs no compiler.
  • Keep build tools in CI images that install native modules, so a missed download does not stop the build.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Workforce.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.