Cloudflare DevelopersCD
Cloudflare Developers3y ago
9 replies
manishrc

**Need help using KV with next-on-pages

Need help using KV with next-on-pages

I've spend several hours trying to access KV in dev environment in my Next.js Project using next-on-pages.

Setup:

- I'm using next@14.0.0, @cloudflare/next-on-pages@1.7.2
- Installed cf-bindings-proxy from @James
- Run npx cf-bindings-proxy --kv=MY_KV_NAMESPACE from Terminal 1
- Run next dev from Terminal 2

Below is the route in /app dir

import { binding } from "cf-bindings-proxy";

export const runtime = "edge";

export async function GET() {
  const value = await binding("MY_KV_NAMESPACE").get("test");
  console.log(value); // 🔴 I get a null here. Expected "Hello World"
  return new Response("OK", {
    status: 200,
  });
}


When I try getting the value from CLI, it works:

$ wrangler kv:key get --binding=MY_KV_NAMESPACE "test"
# I get "Hello World"


---
- I've also tried using a wrangler.toml file with the kv details specificed
- I've also checked the below repos to see what they are doing different
https://github.com/looks-to-me/looks-to-me
https://github.com/james-elicx/cloudy
https://github.com/Rei-x/next-on-cloudflare-example


What am I doing wrong? I'd really appreciate any help 🙏
Was this page helpful?