tursodatabase / libsql-client-ts

TypeScript/JavaScript client API for libSQL
https://docs.turso.tech/sdk/ts/quickstart
MIT License
226 stars 32 forks source link

[Cloudflare Workers] Could not resolve "node:buffer" #36

Closed ben-xD closed 1 year ago

ben-xD commented 1 year ago

I'm trying to use this package, but I get an error:

✘ [ERROR] Could not resolve "node:buffer"

    ../node_modules/.pnpm/@libsql+client@0.1.6/node_modules/@libsql/client/lib-esm/sqlite3.js:2:23:
      2 │ import { Buffer } from "node:buffer";
        ╵                        ~~~~~~~~~~~~~

  The package "node:buffer" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

✘ [ERROR] Build failed with 1 error:

  ../node_modules/.pnpm/@libsql+client@0.1.6/node_modules/@libsql/client/lib-esm/sqlite3.js:2:23:
  ERROR: Could not resolve "node:buffer"

I've tried both options to enable nodeJS APIs (you can't have both simultaneously, wrangler errors.

compatibility_flags = ["nodejs_compat"]
node_compat = true

I'm on wrangler 2.20.0.

Does anyone know what I should try?

Thanks :)

ben-xD commented 1 year ago

The solution is to use the right import.

Wrong 💔

import { createClient } from '@libsql/client';

Right ❤️

import { createClient } from '@libsql/client/web';
honzasp commented 1 year ago

Hi Ben, you are absolutely right, we created the /web import precisely for Cloudflare Workers and other non-Node environments :)