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"


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)


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 


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 })
    }
}


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?
Was this page helpful?