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

2022 Error: Could not locate the bindings file.

Open broccolihighkicks opened this issue 3 years ago • 5 comments
trafficstars

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.

  • https://github.com/WiseLibs/better-sqlite3/issues/146
  • https://github.com/WiseLibs/better-sqlite3/issues/171

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

broccolihighkicks avatar Aug 20 '22 21:08 broccolihighkicks

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

gamanox avatar Dec 14 '22 19:12 gamanox

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/

thanhnguyen2187 avatar Mar 07 '23 11:03 thanhnguyen2187

@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:

houd1ni avatar Mar 16 '23 09:03 houd1ni

@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.

JoshuaWise avatar Mar 16 '23 14:03 JoshuaWise

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

jdspugh avatar Sep 30 '23 08:09 jdspugh

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

deadcoder0904 avatar Mar 14 '24 14:03 deadcoder0904