Not sure if this is a #wrangler or #

Not sure if this is a #wrangler or #miniflare issue, but the following code will throw in wrangler dev (ignored/safe in production): Error Reproduction
export default {
middleware: () => {}, // wrangler dev attempts to iterate this, throwing
}
export default {
middleware: () => {}, // wrangler dev attempts to iterate this, throwing
}
Why this matters itty-router routers have a Proxy trap on the prototype chain. If we export our router directly (ideal), a request to "middleware" returns a function, throwing when internal wrangler code tries to iterate it.
import { Router } from 'itty-router'

export default Router() // this should work, and works fine in Bun
import { Router } from 'itty-router'

export default Router() // this should work, and works fine in Bun
Proposed fix If requesting a hidden exported property (middleware) and iterating over it, there should at least be checks to verify if the item is iterable before attempting to iterate.
3 Replies
Kevin
KevinOP9mo ago
(the thrown error)
No description
Adam
Adam9mo ago
@Kevin W - Itty could you file an issue for this in our repo so we can take a look? https://github.com/cloudflare/workers-sdk/issues That repo is for wrangler and miniflare so we can sort it out there. Thanks!
Kevin
KevinOP9mo ago
GitHub
🐛 BUG: wrangler dev throws if finding a non-iterable middleware exp...
Which Cloudflare product(s) does this pertain to? Wrangler core What version(s) of the tool(s) are you using? 3.39.0 [Wrangler] What version of Node are you using? 20.10.0 What operating system and...
Want results from more Discord servers?
Add your server