`env.ASSETS.fetch(request)` throws ` TypeError: Failed to parse URL from [object Object]`
See original GitHub issueWith the latest beta and alpha release, when fetching assets via:
env.ASSETS.fetch(request)
I am receiving the following error for each static asset when using the built-in proxy:
Could not serve static asset: TypeError: Failed to parse URL from [object Object]
(env.ASSETS.fetch(request.url)
works)
I think this was introduced with #105 and is caused by this line: https://github.com/cloudflare/wrangler2/blob/main/packages/wrangler/src/pages.tsx#L601
The line looks as follows in the transpiled code:
const request = new import_undici.Request(input, init);
When providing a Request
(and not a URL as string), undici
checks instanceof Request
.
I’ve modified the package to:
+ console.log(input instanceof import_undici.Request);
const request = new import_undici.Request(input, init);
This logs false
, confirming that the Request
I am receiving in my onRequest
handler is apparently not an instance of Request
object undici
is expecting.
That is, I believe the error is caused by onRequest
and undici
using different Request prototypes.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:9 (3 by maintainers)
Top GitHub Comments
With #186,
wrangler@alpha
now has the following behavior:I’ll re-open this ticket to track behavior on Cloudflare Pages production, and also to see if
env.ASSETS.fetch('/myasset.jpg')
should work (I think, probably yes).Please open a separate issue for dotfiles/directories if you do believe there is a bug there.
Can confirm.
wrangler@pages
env.ASSETS.fetch(request)
env.ASSETS.fetch(request.url)
Something I’ll have to check too, as I am a heavy user of
.well-known
directories.