Error: Could not locate the bindings file better-sqlite3.node
Asked Answered
I

6

5

The Problem

There are some problem with maybe my installation of better-sqlite3 because when I try to execute my index.js (click to show it on pastebin) with

node index.js

there is always the same result. I tried on MacOS, it works but in my machine Linux Lite Ubuntu based distro aren't it gave me the following same error:

/home/mp8/webproject/electron-better-sqlite/node_modules/bindings/bindings.js:96
  throw err
  ^

Error: Could not locate the bindings file. Tried:
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/build/better_sqlite3.node
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/build/Debug/better_sqlite3.node
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/build/Release/better_sqlite3.node
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/out/Debug/better_sqlite3.node
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/Debug/better_sqlite3.node
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/out/Release/better_sqlite3.node
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/Release/better_sqlite3.node
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/build/default/better_sqlite3.node
 → /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/compiled/8.11.3/linux/x64/better_sqlite3.node
    at bindings (/home/mp8/webproject/electron-better-sqlite/node_modules/bindings/bindings.js:93:9)
    at Object.<anonymous> (/home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/lib/database.js:4:40)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/index.js:2:18)

What is my purpose?

I want to use better-sqlie33 as my database because sqlite3 doesn't gave the node 8.x and later support.

What I tried:

  1. This trouble shooting guide number one and two, but I still had the same error.

  2. make init, first installed better-sqlite3 gave me the error file make/makefile not found. I got the same error when I do npm install better-sqlite3 --save

  3. Make sure better_sqlite3.node are on my node-modules path. yeah it isn't there.

What I want?

I want to run my index.js correctly like I ran it on Mac.

Dependecies

package.json after make init, if not it just a better-sqlite3 dependencies

{
  "_from": "better-sqlite3",
  "_id": "[email protected]",
  "_inBundle": false,
  "_integrity": "sha512-Y11HN9PQ9YUeKFMrmiHyOLAKElk2ATJzBZJvuzNwTMxoS7vUEEyLnUCtcBFqViLwbomr0RQwp2MBy/ogxF50PA==",
  "_location": "/better-sqlite3",
  "_phantomChildren": {},
  "_requested": {
    "type": "tag",
    "registry": true,
    "raw": "better-sqlite3",
    "name": "better-sqlite3",
    "escapedName": "better-sqlite3",
    "rawSpec": "",
    "saveSpec": null,
    "fetchSpec": "latest"
  },
  "_requiredBy": [
    "#USER",
    "/"
  ],
  "_resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-4.1.4.tgz",
  "_shasum": "9fe1dcf7b699087b98b1997cbb00261e265897e2",
  "_spec": "better-sqlite3",
  "_where": "/home/mp8/webproject/electron-better-sqlite",
  "author": {
    "name": "Joshua Wise",
    "email": "[email protected]"
  },
  "bugs": {
    "url": "https://github.com/JoshuaWise/better-sqlite3/issues"
  },
  "bundleDependencies": false,
  "dependencies": {
    "bindings": "^1.3.0",
    "integer": "^1.0.5"
  },
  "deprecated": false,
  "description": "The fastest and simplest library for SQLite3 in Node.js.",
  "devDependencies": {
    "benchmark": "^2.1.4",
    "chai": "^4.1.2",
    "cli-color": "^1.2.0",
    "fs-extra": "^5.0.0",
    "mocha": "^4.1.0",
    "sqlite": "^2.9.0"
  },
  "gypfile": true,
  "homepage": "http://github.com/JoshuaWise/better-sqlite3",
  "keywords": [
    "sql",
    "sqlite",
    "sqlite3",
    "custom",
    "aggregate",
    "database",
    "transactions"
  ],
  "license": "MIT",
  "name": "better-sqlite3",
  "repository": {
    "type": "git",
    "url": "git://github.com/JoshuaWise/better-sqlite3.git"
  },
  "scripts": {
    "benchmark": "node benchmark",
    "install": "node-gyp rebuild",
    "install-debug": "node-gyp rebuild --debug",
    "lzz": "lzz -hx hpp -sx cpp -k BETTER_SQLITE3 -d -hl -sl -e ./src/better_sqlite3.lzz",
    "posttest": "rm -r ./temp/",
    "prepublishOnly": "npm run lzz",
    "pretest": "rm -r ./temp/ || true && mkdir ./temp/",
    "rebuild": "npm run lzz && node-gyp rebuild",
    "rebuild-debug": "npm run lzz && node-gyp rebuild --debug",
    "test": "$(npm bin)/mocha --bail --timeout 5000 --slow 5000"
  },
  "version": "4.1.4"
}

my machine

Linux Lite 4.0, Ubuntu Based.
NVM (Node version Manager)
Node 8.11.1
NPM 5.6
Irregular answered 23/6, 2018 at 4:26 Comment(0)
A
5

I had a problem that looks like your problem

just try that:

projectToto > $ sudo rm -rf node_modules/

projectToto > $ npm install bindings

npm about binding -> https://www.npmjs.com/package/bindings

Advisedly answered 4/7, 2018 at 10:37 Comment(1)
It could not resolve my issue, i have solve it by unnistall node and install again. Still dont know whyIrregular
G
2

I ran into a similar situation until I realized I hadn't explicitly installed build-tools on that machine. Here's what resolved it for me (Ubuntu) when run from inside the project directory

$ rm -rf node_modules/
$ rm package-lock.json

$ npm install build-tools -g
$ npm install
Georgeannageorgeanne answered 2/3, 2021 at 20:33 Comment(0)
F
1

For me, the problem turned out to be a circular dependency in my project (angular 10.1.1, node 12.22.6).

Figuring that out was a little tricky. The Angular compiler gave multiple "WARNING in Circular dependency detected: ..." errors, but none of them included the files where the error was actually introduced. I had to walk the project back until a commit where the problem didn't occur, then investigate what changed. That change seemed pretty innocuous - one file exported a constant that was imported by another. Changing the direction of that export solved the problem.

Falchion answered 29/9, 2021 at 13:21 Comment(0)
N
1

If nothing works....

create a new folder :

  1. install a fresh copy with npm, which will create node_module folder with all the required files.

  2. copy node_module folder and replace with the existing project node_module folder.

  3. close cmd

  4. restart server.

And it worked for me....

Nicollenicolson answered 17/5, 2022 at 10:33 Comment(0)
H
1

i faced this issue in docker on windows 11 using wsl2 with ubuntu as a distro suddenly. i was just moving copy statements in dockerfile. i did nothing to touch it. i even cleared all my cache, removed node_modules, reinstalled it both on my local computer as well as docker.

i literally tried everything here but nothing worked. i also tried doing npm run build-release command after i exec into my container but it yelled i didn't have python. i could install python but then i'd have to do it everytime or worse add it to my image.

my simpler solution was to install better-sqlite3 inside Dockerfile as it is a native node.js module & remove it from package.json. the caveat to this is it won't work on local without docker but anyone can add it with pnpm i better-sqlite3 again if they want to.

Dockerfile

# Install native node_modules in Dockerfile so it uses pnpm's supportedArchitectures feature in package.json. sharp is required only if you use next/image optimization while better-sqlite3 is used in the app itself
RUN pnpm install [email protected] [email protected]

package.json

{
    "dependencies": {
    "@ngneat/falso": "^7.2.0",
    "@t3-oss/env-nextjs": "^0.9.2",
    "drizzle-orm": "^0.30.1",
    "jiti": "^1.21.0",
    "next": "14.1.3",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "std-env": "^3.7.0",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@types/better-sqlite3": "^7.6.9",
    "@types/node": "^20.11.27",
    "@types/react": "^18.2.65",
    "@types/react-dom": "^18.2.22",
    "dotenv": "^16.4.5",
    "drizzle-kit": "^0.20.14",
    "knip": "^5.0.4",
    "rimraf": "^5.0.5",
    "tsx": "^4.7.1",
    "typescript": "^5.4.2"
  },
  "pnpm": {
    "supportedArchitectures": {
      "os": [
        "current"
      ],
      "cpu": [
        "x64",
        "arm64"
      ]
    }
  }
}

the full repo is at https://github.com/deadcoder0904/easypanel-nextjs-sqlite if you wanna reference it.

Holds answered 14/3 at 14:9 Comment(0)
D
0

In my case, the problem was running npm install --ignore-scripts instead of npm install. Turns out that better-sqlite3 has the following script inside:

"scripts": {
    "install": "prebuild-install || node-gyp rebuild --release",
    ...
}

Running npm install without --ignore-scripts fixed the problem.

Dismissive answered 16/10 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.