better-sqlite3: can't install under linux

I get the following Error

Traceback (most recent call last): File "/usr/lib/node_modules/node-gyp/gyp/gyp_main.py", line 50, in <module> sys.exit(gyp.script_main()) File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 554, in script_main return main(sys.argv[1:]) File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 547, in main return gyp_main(args) File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 532, in gyp_main generator.GenerateOutput(flat_list, targets, data, params) File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2215, in GenerateOutput part_of_all=qualified_target in needed_targets) File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 794, in Write extra_mac_bundle_resources, part_of_all) File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 978, in WriteActions part_of_all=part_of_all, command=name) File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1724, in WriteDoCmd force = True) File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1779, in WriteMakeRule cmddigest = hashlib.sha1(command if command else self.target).hexdigest() TypeError: Unicode-objects must be encoded before hashing gyp ERR! configure error gyp ERR! stack Error: gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/node-gyp/lib/configure.js:351:16) gyp ERR! stack at ChildProcess.emit (events.js:210:5) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) gyp ERR! System Linux 5.3.6-arch1-1-ARCH gyp ERR! command “/usr/bin/node” “/usr/lib/node_modules/node-gyp/bin/node-gyp.js” “rebuild” gyp ERR! cwd /home/geeray/uni/win-this/WebAnwendungen2/Praktikum/WebAnwendung2BackendAPI/WebAnw2Backend/node_modules/better-sqlite3 gyp ERR! node -v v12.12.0 gyp ERR! node-gyp -v v6.0.0 gyp ERR! not ok npm WARN webanw2backend@1.0.0 No repository field.

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! better-sqlite3@5.4.3 install: node-gyp rebuild npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the better-sqlite3@5.4.3 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/geeray/.npm/_logs/2019-10-15T15_49_09_447Z-debug.log `

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 46 (1 by maintainers)

Most upvoted comments

I found this a while back too, but didn’t work for me.

It talks about submodules of npm and how to update them:

$ [sudo] npm explore npm -g -- npm install node-gyp@latest

@mcoffin altering this environment variable also works for me, i.e., $ env PYTHON=$(which python2) npm install Thanks!

This should be fixed in the latest version of better-sqlite3 (v6.0.1), due to the use of prebuilt binaries.

I was stuck on this (Arch Linux) for awhile and was able to get past by deleting my .node_modules and global module dir, then running with env PYTHON=$(which python2) yarn start as suggested by @theflyingape

It seems people are moving away from node-gyp to a native js solution but it will take time.

If you’re interested about this story.

Having the same issue on Manjaro, on NVS (Node Version Switcher) on Node 12.x. Solved by downgrading version to 10.x Anyone who is having this issue, try downgrading your node version to LTS by

nvm install --lts  // for nvm
nvs add lts        // for nvs

beginning with node v.12.13 it will also fail to compile. Had to revert to v12.12.0 and node-gyp@5

The following does also work for me on Arch without having to fiddle with subdependencies:

$ PYTHON=$(which python2) yarn install

The sad state of Node.js.

Apparently there’s a new version v6.0.1 of node-gyp that fixed the issue but I still get the same error above cuz npm is not using it!

The reason is npm is using the old version v5.0.7 internally.

Result of $ npm i better-sqlite3 --verbose

gyp info using node-gyp@5.0.7
gyp info using node@12.14.0 | darwin | x64

I still had an issue working with python3 when installing. Switched to python2.7 seemed to fix the issue. It seems to be a problem with the NPM package integer.

@mikeshultz What other C based package works w/ python 3 that you are using?

Whatever it is reasonable, I would agree with you, maybe not reasonable, and I listed the problem it makes for me. I posted it, but I’m ok if it is seen as ‘unreasonable’. I suspect that once Node supports python 3 (as per recent git commit) the issue may fix itself.

There is also a sqlite .js based package that is ~ 20% slower in my tests than a C based one.

So I think I have solution for all. Notes are in the ‘integer’ package for the same developer. Short story, use nvm to install node and use python v2.

We should consolidate all these note under wiki.