cloudflare / cloudflare/workers-sdk
🐛 BUG: `service` should be an optional field under `[[services]]`
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.5k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 187
Description
### Which Cloudflare product(s) does this pertain to?
Wrangler
### What versions are you using?
3.106.0
### What operating system and version are you using?
MacOS
### Please provide a link to a minimal reproduction
_No response_
### Describe the Bug
AKA we should support self defined `WorkerEntrypoint` better.
Consider this worker
```ts
// ./src/server.ts
import { WorkerEntrypoint } from "cloudflare:workers";
export class MyWorker extends WorkerEntrypoint {
someMethod() {
return "hello " + Math.random();
}
}
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
return Response.json(await env.MyWorker.someMethod());
}
}
```
with this `wrangler.toml`:
```toml
name = "example-worker"
main = "src/server.ts"
compatibility_date = "2025-01-28"
[[services]]
binding = "MyWorker"
service = "example-worker" # this shouldn't be necessary
entrypoint = "MyWorker"
```
2 problems here:
- `service = "example-worker"` shouldn't be ncessary since it's in the same worker. it should default to the main worker. but removing that line causes validation to fail.
- when running `wrangler dev`, I get this output
That seems wrong, since it connects to itself successfully. Thankfully the worker still functions.
### Please provide any relevant error logs
_No response_
Contributor guide
Research direction
Reproduce the configuration in wrangler.toml using the WorkerEntrypoint defined in src/server.ts, first testing validation with service omitted and then running wrangler dev. The work is done when same-worker services accept the omitted field and the dev output no longer reports an incorrect connection state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100