libsql-client-ts: Deno example in README.md doesn't work with files

The following fails with Deno:

import { createClient } from "https://esm.sh/@libsql/client@0.4.0-pre.2/node";

const config = {
  url: "file:local.db"
};
const db = createClient(config);
const rs = await db.execute("SELECT * FROM users");
console.log(rs);
error: Uncaught Error: module "@libsql/darwin-arm64" not found
    at require (https://esm.sh/v135/libsql@0.2.0-pre.2/denonext/libsql.mjs:4:178)
    at https://esm.sh/v135/libsql@0.2.0-pre.2/denonext/libsql.mjs:5:1969
    at https://esm.sh/v135/libsql@0.2.0-pre.2/denonext/libsql.mjs:5:452
    at https://esm.sh/v135/libsql@0.2.0-pre.2/denonext/libsql.mjs:5:4899

this works, however:

import { createClient } from "npm:@libsql/client/node";

const config = {
  url: "file:local.db"
};
const db = createClient(config);
const rs = await db.execute("SELECT * FROM users");
console.log(rs);
penberg@vonneumann deno-example % vi example.ts
penberg@vonneumann deno-example % cat example.ts
//import { createClient } from "https://esm.sh/@libsql/client@0.4.0-pre.2/node";
import { createClient } from "npm:@libsql/client/node";

const config = {
  url: "file:local.db"
};
const db = createClient(config);
const rs = await db.execute("SELECT * FROM users");
console.log(rs);

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 11
  • Comments: 16

Most upvoted comments

I Can confirm this. For me I get the this error:

error: Uncaught (in promise) LibsqlError: URL_SCHEME_NOT_SUPPORTED: The client that uses Web standard APIs supports only "libsql:", "wss:", "ws:", "https:" and "http:" URLs, got "file:". For more information, please read https://github.com/libsql/libsql-client-ts#supported-urls

Using import { createClient } from "npm:@libsql/client/node"; works very well

Removing the following line: "deno": "./lib-esm/web.js" from the exports property in node_modules/@libsql/client/package.json has been my most successful workaround so far.

EDIT: When using Deno + libsql locally

The following script demonstrates that the import statement import { createClient } from "@libsql/client/node"; is compatible with Deno 2.0.2.

#!/bin/bash
docker run --rm -i denoland/deno:2.0.2 sh <<\EOF
date
env
mkdir myapp
cd myapp
deno init .
deno add npm:@libsql/client@0.14.0
cat <<EOOF > main.ts
import { createClient } from "@libsql/client/node";
const client = createClient({
    url: "file:local.db",
});
await client.batch(
    [
        "CREATE TABLE IF NOT EXISTS users (email TEXT)",
        "INSERT INTO users VALUES ('first@example.com')",
    ],
    "write",
);
const result = await client.execute("SELECT * FROM users");
console.log("Users:", result.rows);
EOOF
echo
echo "==> test 1"
echo
deno run -A main.ts
EOF

The problem remains if you try to compile the app with deno --compile or deploy it to deno deploy.

Same thing happened to me using the Remix vite cloudflare framework and running it with node locally. libsql/client seems to think it’s in the cloudflare environment.