Closed xcaeser closed 9 months ago
(Assuming you're on an intel mac from the package name)
Take a look at your node_modules
, you should see the root kv
package under @deno
, and then your arch-specific subfolder kv-darwin-x64
Here's what bun does for me (I'm on an arm mac kv-darwin-arm64
, but the idea is similar) on a quick test of a fresh install
I confirm that it's there on a fresh install again, but not working still
Could you please guide me, if possible?
Hmm, maybe try it in a simple bun cli script first, in case it's something in the Next setup.
Tried both a simple index.ts bun script and also a hono server. This is what I get now
import { Hono } from "hono";
import { openKv } from "@deno/kv";
const app = new Hono();
app.get("/", async (c) => {
const kv = await openKv("kv.db");
const result = await kv.set(["Greetings"], "hello!");
console.log({ result });
kv.close();
return c.json(result);
});
export default {
port: 3007,
fetch: app.fetch,
};
Started server http://localhost:3007
55 | throw new Error(`Unexpected 'decodeV8': ${decodeV8}`);
56 | }
57 | return { encodeV8: encodeV8, decodeV8: decodeV8 };
58 | }
59 | if ("Bun" in dntShim.dntGlobalThis) {
60 | throw new Error(`Bun provides v8.serialize/deserialize, but it uses an incompatible format (JavaScriptCore). Provide explicit 'encodeV8' and 'decodeV8' functions via options.`); // https://discord.com/channels/876711213126520882/888937948345684008/1150135641137487892
^
error: Bun provides v8.serialize/deserialize, but it uses an incompatible format (JavaScriptCore). Provide explicit 'encodeV8' and 'decodeV8' functions via options.
Ok, that's better, you're loading the package. That isolates your initial loading problem to something in Next magic.
The new error you are seeing is an intentional warning that's thrown by @deno/kv, as Bun's v8
module serialize/deserialize functions are implemented, but use JavaScriptCore serialization under the hood, which are not compatible with actual V8.
This can present data corruption problems if you want to use DBs on Deno Deploy or other DBs shared with Node/Deno-created dbs that use actual V8 serialization, you might create data you cannot read, or vice versa.
If you are only going to read and write to your local DBs in Bun, you can force the use of Bun's serializers by providing a custom encodeV8
, decodeV8
explicitly as the second parameter to openKv
. Note any data will be unreadable by Node (using @deno/kv, or Deno), since they use the actual V8 format.
e.g. something like:
import { Hono } from "hono";
import { openKv } from "@deno/kv";
import { serialize as encodeV8, deserialize as decodeV8 } from "v8"; // actually JavaScriptCore format on Bun!
const app = new Hono();
app.get("/", async (c) => {
const kv = await openKv("kv.db", { encodeV8, decodeV8 });
const result = await kv.set(["Greetings"], "hello!");
console.log({ result });
kv.close();
return c.json(result);
});
export default {
port: 3007,
fetch: app.fetch,
};
I know the Bun team is working hard on full Node built-in module support, and hope they can do true V8-format serialization at some point in the future.
Great! thank you for your help;
I like deno kv on Deno deploy, but I think I'll stick to redis for now until all this becomes stable...
Thanks again!
Working in Bun and NextJS 14.0.3, got this error using server actions ran bun install @deno/kv
Ran also bun i @deno/kv-darwin-x64 but I am still getting the same error.