Bcrypt dependency install fails on ARM64 architectures

Problem

For a project I work on I build Central with a slightly modified Dockerfile from the original.

The package.json is untouched & I use the same package install command:

npm clean-install --omit=dev --legacy-peer-deps --no-audit \
    --fund=false --update-notifier=false

This works without issues on standard AMD64 architecture.
As part of my CI/CD workflows, I also build using ARM64 architecture under QEMU.

I get a traceback during install:

#31 297.5 npm ERR! code 1
#31 297.5 npm ERR! path /usr/odk/node_modules/bcrypt
#31 297.6 npm ERR! command failed
#31 297.6 npm ERR! command sh -c node-pre-gyp install --fallback-to-build
#31 297.6 npm ERR! Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/odk/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/odk/node_modules/bcrypt/lib/binding/napi-v3 --napi_version=9 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
#31 297.6 npm ERR! node-pre-gyp info it worked if it ends with ok
#31 297.6 npm ERR! node-pre-gyp info using node-pre-gyp@1.0.9
#31 297.6 npm ERR! node-pre-gyp info using node@18.18.2 | linux | arm64
#31 297.6 npm ERR! node-pre-gyp info check checked for "/usr/odk/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" (not found)
#31 297.6 npm ERR! node-pre-gyp http GET https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-linux-arm64-glibc.tar.gz
#31 297.6 npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-linux-arm64-glibc.tar.gz 
#31 297.6 npm ERR! node-pre-gyp WARN Pre-built binaries not installable for bcrypt@5.0.1 and node@18.18.2 (node-v108 ABI, glibc) (falling back to source compile with node-gyp) 
#31 297.6 npm ERR! node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/kelektiv/node.bcrypt.js/releases/download/v5.0.1/bcrypt_lib-v5.0.1-napi-v3-linux-arm64-glibc.tar.gz 
#31 297.6 npm ERR! gyp info it worked if it ends with ok
#31 297.6 npm ERR! gyp info using node-gyp@9.4.0
#31 297.6 npm ERR! gyp info using node@18.18.2 | linux | arm64
#31 297.6 npm ERR! gyp info ok 
#31 297.6 npm ERR! gyp info it worked if it ends with ok
#31 297.6 npm ERR! gyp info using node-gyp@9.4.0
#31 297.6 npm ERR! gyp info using node@18.18.2 | linux | arm64
#31 297.6 npm ERR! gyp ERR! find Python 
#31 297.6 npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
#31 297.6 npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
#31 297.6 npm ERR! gyp ERR! find Python checking if "python3" can be used
#31 297.6 npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
#31 297.6 npm ERR! gyp ERR! find Python checking if "python" can be used
#31 297.6 npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
#31 297.6 npm ERR! gyp ERR! find Python 
#31 297.6 npm ERR! gyp ERR! find Python **********************************************************
#31 297.6 npm ERR! gyp ERR! find Python You need to install the latest version of Python.
#31 297.6 npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
#31 297.6 npm ERR! gyp ERR! find Python you can try one of the following options:
#31 297.6 npm ERR! gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
#31 297.6 npm ERR! gyp ERR! find Python   (accepted by both node-gyp and npm)
#31 297.6 npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
#31 297.6 npm ERR! gyp ERR! find Python - Set the npm configuration variable python:
#31 297.6 npm ERR! gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
#31 297.6 npm ERR! gyp ERR! find Python For more information consult the documentation at:
#31 297.6 npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
#31 297.6 npm ERR! gyp ERR! find Python **********************************************************
#31 297.6 npm ERR! gyp ERR! find Python 
#31 297.6 npm ERR! gyp ERR! configure error 
#31 297.6 npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
#31 297.6 npm ERR! gyp ERR! stack     at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:330:47)
#31 297.6 npm ERR! gyp ERR! stack     at PythonFinder.runChecks (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:159:21)
#31 297.6 npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:202:16)
#31 297.6 npm ERR! gyp ERR! stack     at PythonFinder.execFileCallback (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:294:16)
#31 297.6 npm ERR! gyp ERR! stack     at exithandler (node:child_process:430:5)
#31 297.6 npm ERR! gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:442:5)
#31 297.6 npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:517:28)
#31 297.6 npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:290:12)
#31 297.6 npm ERR! gyp ERR! stack     at onErrorNT (node:internal/child_process:477:16)
#31 297.6 npm ERR! gyp ERR! stack     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
#31 297.6 npm ERR! gyp ERR! System Linux 6.2.0-1016-azure
#31 297.6 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/odk/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/usr/odk/node_modules/bcrypt/lib/binding/napi-v3" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
#31 297.6 npm ERR! gyp ERR! cwd /usr/odk/node_modules/bcrypt
#31 297.6 npm ERR! gyp ERR! node -v v18.18.2
#31 297.7 npm ERR! gyp ERR! node-gyp -v v9.4.0
#31 297.7 npm ERR! gyp ERR! not ok 
#31 297.7 npm ERR! node-pre-gyp ERR! build error 
#31 297.7 npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/odk/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/odk/node_modules/bcrypt/lib/binding/napi-v3 --napi_version=9 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
#31 297.7 npm ERR! node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/usr/odk/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
#31 297.7 npm ERR! node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:517:28)
#31 297.7 npm ERR! node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1098:16)
#31 297.7 npm ERR! node-pre-gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:303:5)
#31 297.7 npm ERR! node-pre-gyp ERR! System Linux 6.2.0-1016-azure
#31 297.7 npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/odk/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
#31 297.7 npm ERR! node-pre-gyp ERR! cwd /usr/odk/node_modules/bcrypt
#31 297.7 npm ERR! node-pre-gyp ERR! node -v v18.18.2
#31 297.7 npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.9
#31 297.7 npm ERR! node-pre-gyp ERR! not ok
#31 297.7 
#31 297.7 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-11-26T15_01_37_226Z-debug-0.log

The error seems to be related to node-pre-gyp during the installation of bcrypt.

Diagnosis

After investigating it seems to be an issue in the underlying bcrypt lib not having a pre-compiled ARM64 install target.

It attempts to compile from source and fails, as Python is not installed.

This was referenced as solved, as the author released ARM64 builds:

See the releases:

Solution

To use the fix, we need to upgrade bcrypt.
It's currently pinned with a tilde ~5, meaning the max version is 5.0.1.
If this was changed to a caret ^5 then, version 5.1.1 will be installed (any v5.x.x can be installed).

edit the meaning of ~ varies depending on how many levels are included in the pin: ~5, ~5.0, ~5.0.1 are different. The current pin of ~5 will allow minor semver upgrades 5.x. The issue here stems from the package.lock file instead of the package.json, where running npm upgrade will use the existing pin to upgrade the lock file and solve the issue.

2 Likes

This should be resolved in Central v2023.5, which uses bcrypt 5.1.1. Thank you for making this suggestion!

1 Like