**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 [email protected], @cloudflare/[email protected]
- Installed
- 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 🙏
cf-bindings-proxy
from @Better 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
When I try getting the value from CLI, it works:
---
- 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 🙏
7 Replies
Would you be able to share a link to a reproduction for this problem, please?
Hi @Better James thanks for offering to help!
I've created a repository here:
https://github.com/manishrc/nextjs-cloudflare-pages-with-bindings/
GitHub
GitHub - manishrc/nextjs-cloudflare-pages-with-bindings: Next.js ap...
Next.js app dir on Cloudflare Pages with Fast-refresh and Bindings in dev - GitHub - manishrc/nextjs-cloudflare-pages-with-bindings: Next.js app dir on Cloudflare Pages with Fast-refresh and Bindin...
It seems to work fine for me
are you sure you've put data into the kv namespace?
e.g., I had to do
npx wrangler kv:key put test hello --namespace-id=FOLDER_CMS_PREVIEW --local
firstOkay! I realize my stupidity now. Thanks for your help 🙏
My understanding was that this will proxy into the namespace in the KV cloud, but these are actually stored locally? I had set the value in the CF dashboard and was expecting to see the value come through.
Do I need to make sure I do not use the same Namespace in other projects so that the data is kept separate?
wrangler pages dev (which the proxy uses) doesn't support remote mode so it won't be able to interact with data stored on Cloudflare in the cloud, only local data
You can use the same namespace for deployed and local, just the data will be pulled from different places
This clears it a lot, thank you.