Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: Creating KV with --preview flag can't be used #3621

Open
dinkopehar opened this issue Jul 17, 2023 · 2 comments
Open

🐛 BUG: Creating KV with --preview flag can't be used #3621

dinkopehar opened this issue Jul 17, 2023 · 2 comments
Labels
bug Something that isn't working

Comments

@dinkopehar
Copy link

Which Cloudflare product(s) does this pertain to?

KV

What version(s) of the tool(s) are you using?

3.1.1 Wrangler ,

What version of Node are you using?

18.16.1

What operating system are you using?

WSL Ubuntu

Describe the Bug

Hello.

I'm using SvelteKit to bootstrap my app with Cloudflare Pages. I opened issue regarding why platform is not available . I wasn't sure how to test locally with bindings, such as KV, R2 etc.
Since SvelteKit generated _worker.js, I used wrangler dev path/to/_worker.js to run it.

In my wrangler.toml, I have set:

name = "someapp"
main = ".svelte-kit/cloudflare/_worker.js"
compatibility_date = "2023-07-10"

kv_namespaces = [
    { binding = "HELLO", id = "5933xxxxx..." }
]

When I try to run it like this (KV "HELLO" exists), it states:

wrangler 3.1.1 (update available 3.2.0)
-----------------------------------------------------
wrangler dev now uses local mode by default, powered by 🔥 Miniflare and 👷 workerd.
To run an edge preview session for your Worker, use wrangler dev --remote

✘ [ERROR] In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "TODO" in your wrangler.toml

But when I create preview KV as suggested and add it to wrangler.toml, I get:

wrangler dev .svelte-kit/cloudflare/_worker.js
 ⛅️ wrangler 3.1.1 (update available 3.2.0)
-----------------------------------------------------
wrangler dev now uses local mode by default, powered by 🔥 Miniflare and 👷 workerd.
To run an edge preview session for your Worker, use wrangler dev --remote

✘ [ERROR] Processing wrangler.toml configuration:

    - "kv_namespaces[0]" bindings should have a string "id" field but got
  {"binding":"TODO","preview_id":"c71962c1xxxx..."}.

This is what KV with preview outputs:

wrangler kv:namespace create TODO --preview
 ⛅️ wrangler 3.1.1 (update available 3.2.0)
-----------------------------------------------------
🌀 Creating namespace with title "stanovi-TODO_preview"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
{ binding = "TODO", preview_id = "c71962cxxxx..." }

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

@dinkopehar dinkopehar added the bug Something that isn't working label Jul 17, 2023
@dinkopehar dinkopehar changed the title 🐛 BUG: 🐛 BUG: Creating KV with --preview flag can't be used Jul 17, 2023
@JacobMGEvans
Copy link
Contributor

JacobMGEvans commented Jul 31, 2023

Thank you for reporting this,

I am going to work on this as well as other commands around products that previously required preview tokens when in development local. The current Miniflare + Workerd have made this requirement obsolete in development local scenarios and shouldn't be erroring.

related internal ticket for same issue with R2: DEVX-773

Cc: @admah

@rab-dev
Copy link

rab-dev commented Aug 3, 2023

A workaround may be to add the namespace as both id and preview_id.

{ binding = "TODO", id = "c71962cxxxx...", preview_id = "c71962cxxxx...", }

Can @dinko-pehar confirm ?

I had the same problem and adding both id and preview_id enables wrangler to run my app although I have not yet tested extensively to confirm correct behaviour.

Edit:

See #3763 (comment)

Explains wrangler code can run:

  1. local (the default)
  2. --remote on the edge
  3. --preview using preview store

So be aware id = preview_id is a hack and running local with --remote or --preview may affect your production KV store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Backlog
Development

No branches or pull requests

4 participants