`npm --global install better-sqlite3` fails on node 17
$ npm --global install better-sqlite3
npm ERR! code 254
npm ERR! path /home/rulatir/.npm-global/lib/node_modules/better-sqlite3
npm ERR! command failed
npm ERR! command sh -c prebuild-install || npm run build-release
npm ERR! prebuild-install WARN install No prebuilt binaries found (target=17.1.0 runtime=node arch=x64 libc= platform=linux)
npm ERR! npm ERR! code ENOENT
npm ERR! npm ERR! syscall open
npm ERR! npm ERR! path null/package.json
npm ERR! npm ERR! errno -2
npm ERR! npm ERR! enoent ENOENT: no such file or directory, open 'null/package.json'
npm ERR! npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! npm ERR! enoent
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR! /home/rulatir/.npm/_logs/2021-11-23T11_47_24_782Z-debug.log
npm ERR! A complete log of this run can be found in:
npm ERR! /home/rulatir/.npm/_logs/2021-11-23T11_47_24_994Z-debug.log
The issue goes away upon downgrading to node 16, but that's probably because cached binaries compiled for that node version are picked up (the installation doesn't seem to be compiling anything).
Is there a reason you are trying to install it globally?
https://docs.npmjs.com/cli/v6/configuring-npm/folders
Install it locally if you're going to require() it. Install it globally if you're going to run it on the command line.
I've been using npm for years now and the only reason I ever install packages globally is if they come with an executable. And even that has become rare these days, since node_modules/.bin is in PATH for scripts. So I just install the executable in each project and they work.
My application that depends on better-sqlite3 is a CLI program that needs to be installed globally, and that's where I originally ran into the issue. The command in the subject "emulates" that. Additionally, I actually use pnpm, but this issue reproduces in npm too, and npm is more "standard", so that's what I reported.
The application in question is in fact a general purpose build system, and it is used to build artifacts that otherwise don't come anywhere near node and don't even have package.json, so there is no "installing the executable in each project". The idea that the --global way of doing things is obsolete/unnecessary/ok-not-to-maintain relies on huge assumptions, like the assumption that node programs are only ever used in node projects.
Searching through GitHub this appears to not only affect better-sqlite3, so maybe Node 17 (or npm 8) did something funny
https://github.com/npm/cli/issues/4015
https://github.com/jopemachine/alfred-chrome-workflow/issues/9 https://github.com/FirebaseExtended/action-hosting-deploy/issues/173
Can you downgrade to npm 8.1.2?
Now confident this is an npm ~bug~ feature https://github.com/npm/cli/commit/a0d35ff20aed6aab8508123eb540bc9c61fb127d
Should be fixed with the next npm release https://github.com/npm/config/pull/25
Is this fixed now ? I’m still having the issue
I just experienced this issue on a new linux user, this package being installed as a dependency of a package installed with pnpm -g, the very next thing after configuring npm global prefix to $HOME/.npm-prefix and installing pnpm globally. This means that installing this package as a dependency of a globally installed application guaranteedly fails in a pristine environment. Please consider emergency workarounds and don't wait for npm to fix their stuff, because that can take months.
The fix landed in npm v8.2.0 (2021-12-02), seven days ago. Are you still experiencing the issue?
I'm also having this issue, even when not using the --global flag
Try running the command as root/administrator
@Fabricio-191 that shouldn't be needed. You shouldn't be installing any packages with sudo.
Its the only way for it to work currently.