WiseLibs / better-sqlite3

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

Deno support - Uncaught Error: Could not locate the bindings file. #1034

Open quantuminformation opened 1 year ago

quantuminformation commented 1 year ago

Tried to use with deno

import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';

const users = sqliteTable('users', {
  id: integer('id').primaryKey(), // 'id' is the column name
  fullName: text('full_name'),
});

const sqlite = new Database('sqlite.db');
const db = drizzle(sqlite);

const allUsers = db.select().from(users).all();
backend git:(master) ✗ deno task dev
Task dev deno run -A --unstable main.ts
error: Uncaught Error: Could not locate the bindings file. Tried:
 → /Users/nikos/WebstormProjects/vanillajs-patterns/backend/node_modules/.deno/bindings@1.5.0/node_modules/bindings/build/better_sqlite3.node
 → /Users/nikos/WebstormProjects/vanillajs-patterns/backend/node_modules/.deno/bindings@1.5.0/node_modules/bindings/build/Debug/better_sqlite3.node
 → /Users/nikos/WebstormProjects/vanillajs-patterns/backend/node_modules/.deno/bindings@1.5.0/node_modules/bindings/build/Release/better_sqlite3.node
neoxpert commented 1 year ago

Even if deno would run npm packages, like bindings, correctly, I doubt that it can load native modules compiled for NodeJS.

Prinzhorn commented 1 year ago

I doubt that it can load native modules compiled for NodeJS.

Apparently it can https://github.com/denoland/deno/issues/18444 https://github.com/denoland/deno/issues/15717

But this is not a better-sqlite3 issue, it's on Deno to make it compatible if they want that.

BrunoSette commented 1 year ago

It doesn't work win Bun 1.0 either. Same error here:

ERROR: Could not locate the bindings file. Tried:

neoxpert commented 1 year ago

Which prebuilt binary did you download? Also note that Bun still does not support the full Node API which may lead to issues anyway support overview.

quantuminformation commented 1 year ago

We are moving to bun 1.0, it appears to work

xero commented 1 year ago

It doesn't work win Bun 1.0 either.

bun has a native sqlite adapter. this project is cited as it’s inspiration

CM-IV commented 1 year ago

You can use .node (Node-API modules) in both Deno and Bun, but you cannot do bun build --compile or deno compile with them. So that just means not building or compiling your code and just running the .ts file in production.

I have tried this on both Deno and Bun with my napi-rs created npm library that exports typed functions from a .node file.

ducktype commented 7 months ago

if i try to put the .node dynamic lib from: https://github.com/WiseLibs/better-sqlite3/releases/download/v9.4.3/better-sqlite3-v9.4.3-node-v108-win32-x64.tar.gz in: \AppData\Local\deno\npm\registry.npmjs.org\bindings\1.5.0\lib\binding\node-v108-win32-x64\better_sqlite3.node i get this error: TypeError: LoadLibraryExW failed

Dependency walker on better_sqlite3.node shows an unresolved dependency "node.exe" Could be related to not loading node-api at runtime in better_sqlite3.node? something like said here: https://github.com/neon-bindings/neon/issues/584 which will also avoid to have separate better_sqlite3.node binary releases for electron and node?

Or for some reason node-gyp win_delay_load_hook Is disabled? https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules

Related? https://github.com/barthofu/tscord/issues/158

deadcoder0904 commented 7 months ago

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