denodrivers / sqlite3

The fastest and correct SQLite3 module for Deno runtime
https://jsr.io/@db/sqlite
Apache License 2.0
265 stars 22 forks source link

Error running the example #80

Closed dong-lufei closed 1 year ago

dong-lufei commented 1 year ago

example:

import { Database } from "https://deno.land/x/sqlite3@0.7.2/mod.ts";

const db = new Database("test.db");

const [version] = db.prepare("select sqlite_version()").value<[string]>()!;
console.log(version);

deno run -A index.ts

Download https://github.com/denodrivers/sqlite3/releases/download/0.7.2/sqlite3.dll
error: Uncaught (in promise) Error: Failed to load SQLite3 Dynamic Library
  const error = new Error("Failed to load SQLite3 Dynamic Library");
                ^
    at https://deno.land/x/sqlite3@0.7.2/src/ffi.ts:566:17
Caused by: TypeError: request or response body error: error reading a body from connection: unexpected end of file
    at async readableStreamCollectIntoUint8Array (deno:ext/web/06_streams.js:822:21)
    at async consumeBody (deno:ext/fetch/22_body.js:232:11)
    at async protocolHttp (https://deno.land/x/cache@0.2.13/file_fetcher.ts:25:18)
    at async fetchFile (https://deno.land/x/cache@0.2.13/file_fetcher.ts:45:14)
    at async FileWrapper.fetch (https://deno.land/x/cache@0.2.13/file.ts:95:18)
    at async FileWrapper.get (https://deno.land/x/cache@0.2.13/file.ts:113:12)
    at async cache (https://deno.land/x/cache@0.2.13/cache.ts:67:10)
    at async Wrapper.cache (https://deno.land/x/cache@0.2.13/cache.ts:21:12)
    at async download (https://deno.land/x/plug@0.5.2/plug.ts:107:16)
    at async prepare (https://deno.land/x/plug@0.5.2/plug.ts:116:16)

deno v1.29.4

asg017 commented 1 year ago

Try running with deno run -A --unstable index.ts, as described here:

Since this library depends on the unstable FFI API, you must pass --allow-env, --allow-ffi and --unstable flags. Network and FS permissions are also needed on macOS and Linux to download and cache prebuilt library. It's recommended to just use --allow-all/-A flag since FFI basically gives full access.

dong-lufei commented 1 year ago

deno run -A --allow-ffi --unstable index.ts OK 了

DjDeveloperr commented 1 year ago

If you pass -A, --allow-ffi isn't needed separately. Apart from that, is it working for you now?

dong-lufei commented 1 year ago

At that time, I ran deno run -A --unstable index.ts and also reported an error. I don’t know if it is a cache problem or a problem with our Chinese firewall. So adding --allow-ffi found that the operation was successful.

DjDeveloperr commented 1 year ago

That is quite weird. Try upgrading to Deno 1.30.0 and Deno SQLite3 0.7.3 and run with deno run -A --unstable index.ts

johanbove commented 1 year ago

Thanks first of all for all the hard work on this! I am unfortunately also experiencing a similar issue.

Testing on WSL on Windows 10, Description: Ubuntu 20.04.5 LTS

deno 1.30.2 (release, x86_64-unknown-linux-gnu) v8 10.9.194.5 typescript 4.9.4

Running the same code as OP, I get:

$ deno run -A --unstable testsqlite.ts 
Download https://github.com/denodrivers/sqlite3/releases/download/0.7.3/libsqlite3.so
error: Uncaught Error: Failed to load SQLite3 Dynamic Library
  const error = new Error("Failed to load SQLite3 Dynamic Library");
                ^
    at https://deno.land/x/sqlite3@0.7.3/src/ffi.ts:566:17
Caused by: Error: Could not open library: Could not open library: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/johan/.cache/deno/plug/https/github.com/72de3c3884468e55e916274372759c9b1c01127577737e7dfaa5b56718dcdb40.so)
    at new DynamicLibrary (deno:ext/ffi/00_ffi.js:368:48)
    at Object.dlopen (deno:ext/ffi/00_ffi.js:500:12)
    at prepare (https://deno.land/x/plug@0.5.2/plug.ts:117:15)
    at async https://deno.land/x/sqlite3@0.7.3/src/ffi.ts:549:12

Where is GLIBC_2.33 coming from and how to install?

johanbove commented 1 year ago

So upgrading to WSL Ubuntu 22.04.1 LTS solved the problem with that library on 20.04 being an unsupported version.

asg017 commented 1 year ago

@johanbove yeah, since the libsqlite3.so file is built on a ubuntu-20.04 runner, that means it's only compatible on computers with a glibc version of 2.33 or higher.

@DjDeveloperr would you accept a PR that changes the GH action workflow to use ubuntu-20.04 instead of ubuntu-latest, so the libsqlite3.so is compatible with more servers? Currently ubuntu-latest points to ubuntu-22.04, and GLIBC version 2.33 is pretty high and doesn't run in a lot of places. Another option is the ubuntu-18.04 runner, but that's gonna be deprecated in a few months

DjDeveloperr commented 1 year ago

PR would be welcome @asg017 :) I'll make a new release 0.7.4 later once the patch lands

DjDeveloperr commented 1 year ago

Next release will have support for older GLIBC versions (to an extent), otherwise this issue seems pretty stale so I'll close it for now.