I can't access my service bindings with the servic...
# workers-help
i
Hey there, I'm having some issues using
miniflare
and the modules syntax, so I'm falling back to service workers. Everything works fine, except that I can't seem to access my service bindings. Here is my
index.js
file as a minimal test case:
Copy code
js
addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest (request) {
  const res = dbg.fetch()
  return new Response(`Hello from gateway -> ${res}`)
}
And my
wrangler.toml
file:
Copy code
toml
name = "my-worker"
main = "src/index.js"
compatibility_date = "2023-04-24"

services = [
  { binding = "dbg", service = "my-debug-service" }
]

routes = [
    { pattern = "localhost", custom_domain = true }
]

[vars]
foo = "BAR"
I can see the following in my logs:
Copy code
Your worker has access to the following bindings:
- Services:
  - dbg: my-debug-service
- Vars:
  - foo: "BAR"
But when I try to access it via
wrangler dev
or
wrangler dev --local
, I get the following error:
Copy code
ReferenceError: dbg is not defined
Btw, accessing "foo" works. It's only the service binding that's giving me headaches. What am I missing?