neon branches

i am using neon. i use neon branches for local development. when i set my neon branch connection string in .dev.vars (WRANGLER_HYPERDRIVE_LOCAL_CONNECTIONSTRING<BINDING>=neon branch connection string) and run wrangler dev. it recognizes my environment variable Found a non-empty WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING variable for binding. Hyperdrive will connect to this database during local development. now when i get the connection string from the binding (BINDING.connectionString), it returns a hyperdrive.local host instead of my neon connection string. what am i doing wrong?
5 Replies
AJR
AJR4d ago
Are you using wrangler dev --remote for local dev, or just wrangler dev?
brandonpsmith
brandonpsmithOP4d ago
i use both but i've only tried it with wrangler dev i just tried it with wrangler dev --remote. BINDING.connectionString is still returning a hyperdrive.local host okay i figured out what is happening. there is a bug when using WRANGLER_HYPERDRIVE_LOCAL_CONNECTIONSTRING<BINDING> variables in the .dev.vars file. wrangler dev throws an error looking for these variables before the cli actually loads the .dev.vars file. so i was using dotenv-cli to load these before running wrangler dotenv -e .dev.vars wrangler dev and somehow that mucks everything up. i moved the variables from the .dev.vars to the wrangler config "localConnectionString" and ran wrangler dev and it's still not working. do you have any recommendations?
AJR
AJR4d ago
@thomasgauvin do you know if devplat has a good recommendation for this issue? I know other teams bump into it at times too.
thomasgauvin
thomasgauvin4d ago
Your actual neon connection string will never be returned for BINDING.connectionString by design. this is how deployed Cloudflare Workers work, and the local emulation matches that. wrangler dev --remote will return hyperdrive.local host, since it's connecting to the Neon database using Cloudflare's hosted Hyperdrive wrangler dev without --remote will also return hyperdrive.local host, which is a local emulation of Hyperdrive
brandonpsmith
brandonpsmithOP4d ago
okay that makes sense. i set the neon url in my wrangler config as the localConnectionString. but when i run wrangler dev and it gives me the hyperdrive.local host. i can't connect to that host. ex. i tried connecting to it via psql ... psql: error: could not translate host name "<id>.hyperdrive.local" to address: nodename nor servname provided, or not known

Did you find this page helpful?