sqlite3 on m1 chip npm is failing

Viewed 3230

I'm attempting to install the sqlite3 module on my mac m1 and it's giving me a ton of errors. Yes, I have xcode installed and up-to-date. I've tried using sudo npm i, and also removed the .node-gyp folder from the root. I was able to send the same code base to another non m1 mac and it installed without trouble.

I'm also on node v14.x

npm ERR! code 1
npm ERR! path /Users/nathanleggatt/Projects/chimp/node_modules/sqlite3
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install --fallback-to-build
npm ERR! ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3300100/sqlite3.c
npm ERR!   TOUCH Release/obj.target/deps/action_before_build.stamp
npm ERR!   CC(target) Release/obj.target/sqlite3/gen/sqlite-autoconf-3300100/sqlite3.o
npm ERR!   LIBTOOL-STATIC Release/sqlite3.a
npm ERR! Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3/lib/binding/node-v83-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3/lib/binding/node-v83-darwin-x64 --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using node-pre-gyp@0.11.0
npm ERR! node-pre-gyp info using node@14.15.3 | darwin | x64
npm ERR! node-pre-gyp WARN Using request for node-pre-gyp https download 
npm ERR! node-pre-gyp info check checked for "/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3/lib/binding/node-v83-darwin-x64/node_sqlite3.node" (not found)
npm ERR! node-pre-gyp http GET https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.1/node-v83-darwin-x64.tar.gz
npm ERR! node-pre-gyp http 403 https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.1/node-v83-darwin-x64.tar.gz
npm ERR! node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.1/node-v83-darwin-x64.tar.gz 
npm ERR! node-pre-gyp WARN Pre-built binaries not found for sqlite3@4.1.1 and node@14.15.3 (node-v83 ABI, unknown) (falling back to source compile with node-gyp) 
npm ERR! node-pre-gyp http 403 status code downloading tarball https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.1/node-v83-darwin-x64.tar.gz 
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@14.15.3 | darwin | x64
npm ERR! gyp info ok 
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@14.15.3 | darwin | x64
npm ERR! gyp info find Python using Python version 3.9.10 found at "/usr/local/opt/python@3.9/bin/python3.9"
npm ERR! gyp info spawn /usr/local/opt/python@3.9/bin/python3.9
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/nathanleggatt/Library/Caches/node-gyp/14.15.3/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/nathanleggatt/Library/Caches/node-gyp/14.15.3',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/nathanleggatt/Library/Caches/node-gyp/14.15.3/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info ok 
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@14.15.3 | darwin | x64
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! libtool: unrecognized option `-static'
npm ERR! libtool: Try `libtool --help' for more information.
npm ERR! make: *** [Release/sqlite3.a] Error 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Darwin 20.3.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3/lib/binding/node-v83-darwin-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3/lib/binding/node-v83-darwin-x64" "--napi_version=7" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v83"
npm ERR! gyp ERR! cwd /Users/nathanleggatt/Projects/chimp/node_modules/sqlite3
npm ERR! gyp ERR! node -v v14.15.3
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok 
npm ERR! node-pre-gyp ERR! build error 
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 build --fallback-to-build --module=/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3/lib/binding/node-v83-darwin-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/Users/nathanleggatt/Projects/chimp/node_modules/sqlite3/lib/binding/node-v83-darwin-x64 --napi_version=7 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)
npm ERR! node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/nathanleggatt/Projects/chimp/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
npm ERR! node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
npm ERR! node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1048:16)
npm ERR! node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
npm ERR! node-pre-gyp ERR! System Darwin 20.3.0
npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/nathanleggatt/Projects/chimp/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
npm ERR! node-pre-gyp ERR! cwd /Users/nathanleggatt/Projects/chimp/node_modules/sqlite3
npm ERR! node-pre-gyp ERR! node -v v14.15.3
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v0.11.0
npm ERR! node-pre-gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/nathanleggatt/.npm/_logs/2022-01-27T06_39_15_358Z-debug-0.log
6 Answers

This one solved it for me:

npm config set python "$(which python3)" # or whichever version you use

Solution taken from this github issue.

I am facing the same issue trying to install Truffle (Consensys) and I think this is linked to sqlite3 library not being served.

Your script is trying to download it but the link is not working:

> npm ERR! node-pre-gyp http GET https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.1/node-v83-darwin-x64.tar.gz
> npm ERR! node-pre-gyp http 403 https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.1/node-v83-darwin-x64.tar.gz

If I browse to it manually, I get an error:

Error downloading sql3

An issue have already been reported on their github :

I tried workaround proposed in various repo about this issue (file not accessible) but none worked for me so far.

I ended up just doing nvm use 14. Apparently node v14 works.

For me, the problem was that python 3.0 wasn't available on my M1, somehow that was the bottom of the issue.

The workaround I've got was to diverting it to the previous version.

I hope that helps more people.

I just faced the issue and was going through different solutions. So, there can be 2 things here:

  1. Missing Python version: Perform npm config set python "$(which python3)". For some, this option will work and for some it will not becuase the problem lies somewhere else.

  2. Space in project directory path: If there is space in the project directory path, there will be still the same error. In my case it was, My Files/projects/project-name. Once, i moved the project to

For me, updating node to the latest, or latest LTS version works. Using nvm:

 nvm install --lts
 nvm use --lts

(or to be bleeding edge):

 nvm install node
 nvm use node

As of this writing: LTS ("gallium") v16.16.0, latest: v18.5.0

Related