WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.5k stars 394 forks source link

2022 Error: Could not locate the bindings file. #866

Closed broccolihighkicks closed 7 months ago

broccolihighkicks commented 2 years ago

I get this error after install:

Error: Could not locate the bindings file. Tried:
 → /x/build/better_sqlite3.node
 → /x/build/Debug/better_sqlite3.node
 → /x/build/Release/better_sqlite3.node
 → /x/out/Debug/better_sqlite3.node
 → /x/Debug/better_sqlite3.node
 → /x/out/Release/better_sqlite3.node
 → /x/Release/better_sqlite3.node
 → /x/build/default/better_sqlite3.node
 → /x/compiled/18.7.0/darwin/arm64/better_sqlite3.node
 → /x/addon-build/release/install-root/better_sqlite3.node
 → /x/addon-build/debug/install-root/better_sqlite3.node
 → /x/addon-build/default/install-root/better_sqlite3.node
 → /x/lib/binding/node-v108-darwin-arm64/better_sqlite3.node

I noticed that node-v108-darwin-arm64 is not in the release assets: https://github.com/WiseLibs/better-sqlite3/releases/tag/v7.6.2

Also, the lookup folders above are looking in my projects folder /x/ not /x/node_modules/better-sqlite3/.

Possible fix: ln -s node_modules/better-sqlite3/build ./build seems to avoid this issue.

Can you patch better-sqlite3 to change look up paths to include `/x/node_modules/better-sqlite3/``?

Similar issues from 2018 that are closed.

Versions

Mac M1. Node v18.7.0.

yarn.lock

better-sqlite3@^7.6.2:
  version "7.6.2"
  resolved "https://registry.yarnpkg.com/better-sqlite3/-/better-sqlite3-7.6.2.tgz#47cd8cad5b9573cace535f950ac321166bc31384"
  integrity sha512-S5zIU1Hink2AH4xPsN0W43T1/AJ5jrPh7Oy07ocuW/AKYYY02GWzz9NH0nbSMn/gw6fDZ5jZ1QsHt1BXAwJ6Lg==
  dependencies:
    bindings "^1.5.0"
    prebuild-install "^7.1.0"

tree node_modules/better-sqlite3/build

node_modules/better-sqlite3/build
├── Makefile
├── Release
│   ├── better_sqlite3.node
│   ├── obj
│   │   └── gen
│   │       └── sqlite3
│   │           ├── sqlite3.c
│   │           ├── sqlite3.h
│   │           └── sqlite3ext.h
│   ├── obj.target
│   │   ├── better_sqlite3
│   │   │   └── src
│   │   │       └── better_sqlite3.o
│   │   ├── deps
│   │   │   └── locate_sqlite3.stamp
│   │   ├── sqlite3
│   │   │   └── gen
│   │   │       └── sqlite3
│   │   │           └── sqlite3.o
│   │   └── test_extension
│   │       └── deps
│   │           └── test_extension.o
│   ├── sqlite3.a
│   └── test_extension.node
├── better_sqlite3.target.mk
├── binding.Makefile
├── config.gypi
├── deps
│   ├── locate_sqlite3.target.mk
│   ├── sqlite3.Makefile
│   └── sqlite3.target.mk
├── gyp-mac-tool
└── test_extension.target.mk
gamanox commented 1 year ago

Try installing XCode and open it then run again the npm/yarn install process @broccolihighkicks

thanhnguyen2187 commented 1 year ago

I ran into this issue on trying to run a file that is the result of esbuild --bundle. A fix for this is to build better-sqlite3 in node_modules first, and then copy the built folder Release to your own build:

cd node_modules/better-sqlite3
npm run build-release
# or `yarn build-release`

# move back to the source folder
cd ..
cd ..

# copy the folder itself
cp -r node_modules/better-sqlite3/build/Release/ build/
houd1ni commented 1 year ago

@JoshuaWise What piece of code tries to find the binding ? What obstacle prevents from patching it to try more in /node_modules prefix ? The hack of @thanhnguyen2187 is way too dirty and seems to be the only option when using esbuild bundler that is the future and somewhere required. At the same time the solution seems to be a "oneliner", but I could not find the code in this repo briefly enough to make a PR. Looking forward to get a bit of help c:

JoshuaWise commented 1 year ago

@houd1ni The binding is found by the bindings package, which automatically locates the binding for standard installations. If you are using some third-party bundler (like esbuild), it probably won't work, but you can always point to the binding manually by using the nativeBinding option.

jdspugh commented 1 year ago

I ran into this issue on trying to run a file that is the result of esbuild --bundle. A fix for this is to build better-sqlite3 in node_modules first, and then copy the built folder Release to your own build:

cd node_modules/better-sqlite3
npm run build-release
# or `yarn build-release`

# move back to the source folder
cd ..
cd ..

# copy the folder itself
cp -r node_modules/better-sqlite3/build/Release/ build/

For me this worked:

cd node_modules/better-sqlite3
npm run build-release
cd ..
deadcoder0904 commented 7 months ago

I solved it by installing better-sqlite3 in Dockerfile instead of package.json & using pnpm's supportedArchitectures feature.