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

Support cloudflare KV bindings for cloudflare-pages and cloudflare-module presets #1132

Closed
stenet opened this issue Apr 12, 2023 · 4 comments
Labels
bug Something isn't working enhancement New feature or request preset:cloudflare ready on edge

Comments

@stenet
Copy link
Contributor

stenet commented Apr 12, 2023

Environment

Cloudflare Pages

Reproduction

Not sure whether this is an error or not and whether this is the correct place ...

I've created a simple Nuxt-App with Storage https://github.com/stenet/nuxt-storage-cf.

While deploying the App in Cloudflare Pages at the end an error is thrown:
image

nuxt-storage-cf.ae48777b-dbd5-4a9d-832d-80a70ba6fdc9.log

This is the KV namespace binding I've configured:
image

When I remove Nitro storage and use ev.context.cloudflare.env.KV123 inside test.get.ts it works without errors.

Describe the bug

See above.

Additional context

No response

Logs

No response

@pi0
Copy link
Member

pi0 commented Apr 13, 2023

Cloudflare module format (used by pages) does not support KV yet. Since we need to access env from global.

@pi0 pi0 added bug Something isn't working enhancement New feature or request preset:cloudflare and removed pending triage labels Apr 13, 2023
@pi0 pi0 changed the title Error when deploying on Cloudflare Pages with unjs/storage Cloudflare KV Binding Support cloudflare KV bindings for cloudflare-pages and cloudflare-module presets Apr 13, 2023
@atinux
Copy link
Collaborator

atinux commented Apr 16, 2023

Error is thrown by https://github.com/unjs/unstorage/blob/a336cafd559a34087db99303d9ce06532cd03fb8/src/drivers/cloudflare-kv-binding.ts#L46

We may have to rethink to create the storage only when a request come in, so far you can create the storage inside the router as a workaround

@pi0
Copy link
Member

pi0 commented Apr 16, 2023

Support for CF bindings in module mode should be possible in the latest nitropack edge. You can early try using resolutions in package.json: (make sure to also renew lockfile)

{
  "resolutions": {
    "nitropack": "npm:nitropack-edge@latest"
  }
}

@Hebilicious
Copy link
Contributor

This got added in v2.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request preset:cloudflare ready on edge
Projects
None yet
Development

No branches or pull requests

4 participants