workers-sdk
workers-sdk copied to clipboard
🐛 BUG: `unstable_getMiniflareWorkerOptions` breaks Miniflare when using Workers AI
Which Cloudflare product(s) does this pertain to?
Wrangler
What version(s) of the tool(s) are you using?
3.78.7
What version of Node are you using?
22.9.0
What operating system and version are you using?
Mac Sonoma
Describe the Bug
Observed behavior
When adding an AI binding in wrangler.toml, unstable_getMiniflareWorkerOptions returns the correct wrappedBinding but without the associated external worker. This is because unstable_getMiniflareWorkerOptions is not using the externalWorkers returned by buildMiniflareBindingOptions here so it's not possible to pass it to Miniflare later.
If the result is passed to Miniflare, it fails with the following:
workerd/server/workerd-api.c++:770: error: wrapped binding module can't be resolved (internal modules only); moduleName = miniflare-internal:wrapped:__WRANGLER_EXTERNAL_AI_WORKER
Expected behavior
There should be a way to get the wrangler config in a way that works when passed to Miniflare when using Workers AI. Perhaps it could return externalWorkers or something similar.
Steps to reproduce
- Add Workers AI to wrangler.toml:
[ai]
binding = "AI"
- Try reading the wrangler.toml with
unstable_getMiniflareWorkerOptionsand passing the result to Miniflare, or just log it. It will containwrappedBindings { AI: { scriptName: '__WRANGLER_EXTERNAL_AI_WORKER' } }without the associated__WRANGLER_EXTERNAL_AI_WORKERservice binding anywhere.
Please provide a link to a minimal reproduction
No response
Please provide any relevant error logs
No response
cc @jacob-ebey perhaps interesting for your new Vite plugin
Hey! I think unstable_getMiniflareWorkerOptions exists mostly to get the vitest integration working - is this issue because the ai binding isn't working with vitest, or are you using it directly in some way? If the latter, it would be helpful to get more info on what your usecase is :)
Hi 👋
The use case is creating a Miniflare instance in a custom integration (Vite plugin) for local development, but reading the config options from wrangler.toml directly. Something like this.
When using the result of unstable_getMiniflareWorkerOptions to create the Miniflare instance, it is missing the worker associated to the wrapped binding for AI, which makes Miniflare/workerd complain.
I guess this would also affect the Vitest integration if you use AI there? Assuming that integration creates a Miniflare instance.
this should work now as the external workers are also exported in unstable_getMiniflareWorkerOptions