core icon indicating copy to clipboard operation
core copied to clipboard

hyperdrive is not included in the runtime instance

Open 9M6 opened this issue 1 year ago • 4 comments

Describe the bug I've setup cloudflare hyperdrive correctly in the nuxt.config.ts in bindings; I noticed that in wrangler.toml it does not generate the bindings, but maybe this is due to to not working locally.

I tested in on remote, and in the logs POSTGRES env does not show up; and the process.env.POSTGRES returns null, I've also logged : event.context.cloudflare.env which returns all other bindings, and env variables, but there's no POSTGRES env variable that binds to hyperdrive.

Steps to reproduce

  1. Setup the hub.bindings.hyperdrive
  2. create an API handler with logs for process.env.POSTGRES or event.context.cloudflare.env
  3. call API
  4. No hyperdrive

Expected behavior POSTGRES should have hyperdrive bindings

9M6 avatar Sep 14 '24 09:09 9M6

Indeed we don't generate it for now: https://github.com/nuxt-hub/core/blob/33612ee58104fe4ed523e933ae45bcb9a1615a32/src/utils/wrangler.ts#L43-L58

The feature for local development in wrangler was released 4 days ago: https://github.com/cloudflare/workers-sdk/pull/6612

I will have a look this week to fix this

atinux avatar Sep 14 '24 09:09 atinux

Hey @atinux cool, thank you, but there seem to be another issue actually, and why hyperdrive does not show up in runtime. The problem seem to be nodejs_compat_v2

https://developers.cloudflare.com/hyperdrive/configuration/connect-to-postgres/

CleanShot 2024-09-14 at 13 03 28@2x

  1. I've set it on nuxt.config but does not show up
  2. I set it manually, and told me I must use experimental:nodejs_compat_v2
  3. When used experimental:nodejs_compat_v2 still failed. Error: Failed to publish your Function. Got error: No such compatibility flag: experimental:nodejs_compat_v2

I'm not sure where to go from where, any idea?

9M6 avatar Sep 14 '24 10:09 9M6

This is how you can enable it:

export default defineNuxtConfig({
  hub: {
    bindings: {
      compatibilityFlags: 'nodejs_compat_v2'
    }
  }
})

atinux avatar Sep 14 '24 10:09 atinux

Doesn't seem to set it/change it. By any chance if this is set manually through cloudflare, it wont let nuxt overwrite the config, maybe?

9M6 avatar Sep 14 '24 10:09 9M6