Can't access RPC Service Bindings in local (next dev)

i'm trying to access a Service binding (RPC) in my Next-on-Pages. My wrangler.toml looks like this:
# Generated by Wrangler
name = "tx"
pages_build_output_dir = ".vercel/output/static"
compatibility_date = "2024-04-06"
compatibility_flags = [ "nodejs_compat"]

[[services]]
binding = "VECTORIZE_WORKER"
service = "vectorize-worker"
environment = "production"

[env.production]
compatibility_date = "2024-04-06"
compatibility_flags = [ "nodejs_compat" ]

[[env.production.services]]
binding = "VECTORIZE_WORKER"
service = "vectorize-worker"
environment = "production"
# Generated by Wrangler
name = "tx"
pages_build_output_dir = ".vercel/output/static"
compatibility_date = "2024-04-06"
compatibility_flags = [ "nodejs_compat"]

[[services]]
binding = "VECTORIZE_WORKER"
service = "vectorize-worker"
environment = "production"

[env.production]
compatibility_date = "2024-04-06"
compatibility_flags = [ "nodejs_compat" ]

[[env.production.services]]
binding = "VECTORIZE_WORKER"
service = "vectorize-worker"
environment = "production"
When I call it like this, running next dev:
const { env } = getRequestContext()
const VECTORIZE_WORKER = env.VECTORIZE_WORKER
if (!VECTORIZE_WORKER)
throw new Error('UNDEFINED BINDING: VECTORIZE_WORKER')
const response = await VECTORIZE_WORKER.ImageSearch(imagename)
const { env } = getRequestContext()
const VECTORIZE_WORKER = env.VECTORIZE_WORKER
if (!VECTORIZE_WORKER)
throw new Error('UNDEFINED BINDING: VECTORIZE_WORKER')
const response = await VECTORIZE_WORKER.ImageSearch(imagename)
It does not throw this error, indicating that the binding was found, but I get the following warning regarding RPC:
WARNING: Tried to access method or property 'ImageSearch' on a Service Binding or Durable Object stub. Are you trying to use RPC? If so, please enable the 'rpc' compat flag or update your compat date to 2024-04-03 or later
WARNING: Tried to access method or property 'ImageSearch' on a Service Binding or Durable Object stub. Are you trying to use RPC? If so, please enable the 'rpc' compat flag or update your compat date to 2024-04-03 or later
The "Image Search" is defined in my worker like this:
export default class extends WorkerEntrypoint {
async ImageSearch(imagename: string) {
return new Response('Got results', { status: 200 })
}
}
export default class extends WorkerEntrypoint {
async ImageSearch(imagename: string) {
return new Response('Got results', { status: 200 })
}
}
It does work when running wrangler pages dev .vercel/output/static --service VECTORIZE_WORKER=vectorize-worker --compatibility-flag=nodejs_compat" alongside the service worker running via wrangler dev It does not work (and throws the error above) when running next dev Is it possible to make rpc service bindings work via next dev? Also since my vectorize worker do access Vectorize, it will only work via wrangler dev --remote which is then further incompatible with this local testing?
3 Replies
Brendan Irvine-Broque
@thipperz — what is the compatibility date of the Pages project? This error suggests that you have the wrong compat date being set:
Are you trying to use RPC? If so, please enable the 'rpc' compat flag or update your compat date to 2024-04-03 or later
Are you trying to use RPC? If so, please enable the 'rpc' compat flag or update your compat date to 2024-04-03 or later
thipperz
thipperzOP9mo ago
@Brendan Irvine-Broque that message appears even after I updated the compat date or added the 'rpc' compat flag in my wrangler.toml Seems like something else is going on
thipperz
thipperzOP9mo ago
GitHub
🐛 BUG: Miniflare's getBindings does not properly expose RPC entry...
Which Cloudflare product(s) does this pertain to? Miniflare What version(s) of the tool(s) are you using? [email protected] What version of Node are you using? 20 What operating system and ver...
Want results from more Discord servers?
Add your server