Ah ok so it looks like the order you

Ah ok, so it looks like the order you call unstable_dev is important here. Moving const user = await unstable_dev(...) before const core = await unstable_dev(...) seems to work. Would you mind opening a GitHub issue for this? We're just starting a rewrite of wrangler dev's internals, and this is something we should consider. 👍
7 Replies
danielsundq
danielsundq15mo ago
Hmm ok but it still doesn't work in my code. Could you please try to make the services mutal dependant? I have something like this:
## user service
[[services]]
binding = "core"
service = "core-api-local"

## core service

[[services]]
binding = "user"
service = "user-api-local"
## user service
[[services]]
binding = "core"
service = "core-api-local"

## core service

[[services]]
binding = "user"
service = "user-api-local"
If the order was the issue in your test, then it seems reasonable that it would also be a problem with mutual dependant workers like this.
MrBBot
MrBBotOP15mo ago
Yeah... that seems like the problem. 😕 Will take a look into that code now and see if there's something we can do to fix. 👍
danielsundq
danielsundq15mo ago
Thats great, thank you for helping out!
MrBBot
MrBBotOP15mo ago
Ok, so I don't think there's an easy fix in Wrangler here with the current architecture of unstable_dev(). Right now, we have 2 dev modes in Wrangler: "regular" mode and "test" mode. The "regular" mode uses React with https://github.com/vadimdemedes/ink, watches files, and responds to changes from the dev registry. Unfortunately, for some reason I can't remember right now, you can only have one instance of React/Ink per process. Because this isn't great for testing, "test" mode lifts this restriction by starting your worker once, and leaving it as is. This means it doesn't respond to any changes though. unstable_dev() defaults to "test" mode, but you can switch to "regular" mode with unstable_dev({ experimental: { testMode: false } }). As mentioned though, this will only allow you start one worker per process. The wrangler dev-internal-rewrite I mentioned in an earlier message is to remove React/Ink, and this restriction. We're also tidying up and stabilising unstable_dev()s API. Based on your requirements, you may be able to get this to work by spawining multiple Node processes, one for each worker, and switching to "regular" mode. Or, you could consider trying out Miniflare directly: https://github.com/cloudflare/miniflare/blob/tre/packages/miniflare/README.md. There's an example of how to use multiple workers in the v2->v3 migration guide here https://miniflare.dev/get-started/migrating#removed-options under mounts. Note Miniflare doesn't load wrangler.toml files, so you'll need to manually define your config using Miniflare's API.
danielsundq
danielsundq15mo ago
Ok thanks for the detailed explanation. Yeah I have looked at using Miniflare, that might be a possible solution. The documentation is a bit of a pain point right now though. Do you think my requirements will be supported natively in wrangler test mode in the future?
MrBBot
MrBBotOP15mo ago
For sure, we're planning to unify the two modes so unstable_dev() and $ wrangler dev use all the same code paths. 👍 We're aware the Miniflare docs aren't great atm too, it's on the list of things to work on.
danielsundq
danielsundq15mo ago
Glad to hear it. Thanks for the help!
Want results from more Discord servers?
Add your server