better-sqlite3 icon indicating copy to clipboard operation
better-sqlite3 copied to clipboard

`npm --global install better-sqlite3` fails on node 17

Open rulatir opened this issue 4 years ago • 12 comments

$ 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).

rulatir avatar Nov 23 '21 11:11 rulatir

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.

Prinzhorn avatar Nov 23 '21 17:11 Prinzhorn

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.

rulatir avatar Nov 24 '21 10:11 rulatir

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?

Prinzhorn avatar Nov 24 '21 19:11 Prinzhorn

Now confident this is an npm ~bug~ feature https://github.com/npm/cli/commit/a0d35ff20aed6aab8508123eb540bc9c61fb127d

Prinzhorn avatar Nov 24 '21 19:11 Prinzhorn

Should be fixed with the next npm release https://github.com/npm/config/pull/25

Prinzhorn avatar Nov 25 '21 16:11 Prinzhorn

Is this fixed now ? I’m still having the issue

ARR4NN avatar Nov 26 '21 22:11 ARR4NN

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.

rulatir avatar Dec 09 '21 14:12 rulatir

The fix landed in npm v8.2.0 (2021-12-02), seven days ago. Are you still experiencing the issue?

Prinzhorn avatar Dec 09 '21 16:12 Prinzhorn

I'm also having this issue, even when not using the --global flag

diamonddev01 avatar Feb 05 '22 03:02 diamonddev01

Try running the command as root/administrator

Fabricio-191 avatar Mar 06 '22 14:03 Fabricio-191

@Fabricio-191 that shouldn't be needed. You shouldn't be installing any packages with sudo.

OmgImAlexis avatar Mar 06 '22 20:03 OmgImAlexis

Its the only way for it to work currently.

diamonddev01 avatar Mar 10 '22 00:03 diamonddev01