Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better-sqlite3 doesn't work #26034

Open
dector opened this issue Oct 4, 2024 · 6 comments
Open

better-sqlite3 doesn't work #26034

dector opened this issue Oct 4, 2024 · 6 comments
Labels
bug Something isn't working correctly node compat

Comments

@dector
Copy link

dector commented Oct 4, 2024

WORKAROUND

If you don't mind WAL mode - use libsql instead (it's compatible with better-sqlite3 API):

deno add npm:libsql-node



Original issue

This issue was raised earlier in #18444 and #19130 but was closed as "fixed".
However, it's not.

$ deno --version
deno 2.0.0-rc.10 (release candidate, release, x86_64-unknown-linux-gnu)
v8 12.9.202.13-rusty
typescript 5.6.2

$ deno eval "import Database from 'npm:better-sqlite3'; new Database(':memory:')"
error: Uncaught (in promise) Error: Could not locate the bindings file. Tried:
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/build/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/build/Debug/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/build/Release/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/out/Debug/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/Debug/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/out/Release/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/Release/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/build/default/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/compiled/20.11.1/linux/x64/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/addon-build/release/install-root/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/addon-build/debug/install-root/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/addon-build/default/install-root/better_sqlite3.node
 → /home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/lib/binding/node-v108-linux-x64/better_sqlite3.node
    at bindings (file:///home/me/.cache/deno/npm/registry.npmjs.org/bindings/1.5.0/bindings.js:126:9)
    at new Database (file:///home/me/.cache/deno/npm/registry.npmjs.org/better-sqlite3/11.3.0/lib/database.js:48:64)
    at file:///home/me/$deno$eval.ts:1:44
@dector dector closed this as completed Oct 4, 2024
@dector dector reopened this Oct 4, 2024
@dector
Copy link
Author

dector commented Oct 4, 2024

Might be dupe for #15717

@dector dector changed the title import 'npm:better-sqlite3' doesn't work 'better-sqlite3' doesn't work Oct 4, 2024
@dector dector changed the title 'better-sqlite3' doesn't work better-sqlite3 doesn't work Oct 4, 2024
@dector
Copy link
Author

dector commented Oct 4, 2024

It's interesting! Libsql totally works!

$ deno eval "import Database from 'npm:libsql'; const db = new Database(':memory:'); console.log('Wow!')"
Wow!

@nathanwhit
Copy link
Member

nathanwhit commented Oct 4, 2024

The underlying reason is that better-sqlite3 uses internal node C++ APIs directly. Those are not stable across node versions (for instance, better-sqlite3 needs a different build for each node version, and internal changes in node can break it) and for this reason they aren't supported by deno.

If better-sqlite3 were updated to use NAPI, which is a stable interface for node native addons, instead of node's internal APIs it would work on deno.


Other packages (such as sqlite3 and libsql) do use NAPI, and so they work in deno

@dector
Copy link
Author

dector commented Oct 5, 2024

Thanks for the explanation!

I dunno how important part of the ecosystem is better-sqlite3 but libsql is quite awesome.

Feel free to close this issue as "wan't fix".

@littledivy littledivy added bug Something isn't working correctly node compat labels Oct 5, 2024
@littledivy
Copy link
Member

It is technically possible to emulate Node.js NaN and expose V8 C++ symbols. There are usually not any breaking changes to old V8 APIs that modules like better-sqlite3 might be using.

@teddybee
Copy link

teddybee commented Nov 18, 2024

Same issue here :(
deno eval "import Database from 'npm:better-sqlite3'; const db = new Database(':memory:'); console.log('Wow!')"

Warning experimentalDecorators compiler option is deprecated and may be removed at any time
error: Uncaught (in promise) TypeError: LoadLibraryExW failed: A dynamic link library (DLL) initialization routine failed. (os error 1114)
    at Object.Module._extensions..node (node:module:807:20)
    at Module.load (node:module:662:32)
    at Function.Module._load (node:module:534:12)
    at Module.require (node:module:681:19)
    at require (node:module:818:16)
    at bindings (file:///D:/NodeJS/***/***/node_modules/.deno/[email protected]/node_modules/bindings/bindings.js:112:48)
    at new Database (file:///D:/NodeJS/***/***/node_modules/.deno/[email protected]/node_modules/better-sqlite3/lib/database.js:48:64)
    at file:///D:/NodeJS/***/***/apps/backend/$deno$eval.ts:1:55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

No branches or pull requests

4 participants