cloudflare / cloudflare/workers-sdk
🐛 BUG: Failed to parse URL error when using DO with next-on-pages
- 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?
Pages, Miniflare
### What version(s) of the tool(s) are you using?
3.57.0 (wrangler), 3.20240512.0 (miniflare), 1 (@cloudflare/next-on-pages)
### What version of Node are you using?
20.13.1
### What operating system and version are you using?
Mac Sonoma 14.5
### Describe the Bug
### Observed behavior
I have a `app/ws/route.ts` GET handler that attempts to pass the `request` object to a durable objects (DO) `fetch` method.
```
// app/ws/route.ts
import type { NextRequest } from 'next/server';
import { getRequestContext } from '@cloudflare/next-on-pages';
export const runtime = 'edge';
export async function GET(request: NextRequest) {
const signalingNS = getRequestContext().env.signaling;
const id = signalingNS.idFromName('production');
const stub = signalingNS.get(id);
const response = await stub.fetch(request);
return response;
}
```
This is result in the following issue:
```
⨯ Error [TypeError]: Failed to parse URL from [object Request]
at new Request (file:///Users/mj/repos/xtalk/node_modules/miniflare/node_modules/undici/lib/fetch/request.js:88:15)
at new Request (file:///Users/mj/repos/xtalk/node_modules/miniflare/dist/src/index.js:3692:5)
at #fetcherFetchCall (file:///Users/mj/repos/xtalk/node_modules/miniflare/dist/src/index.js:6375:21)
at #call (file:///Users/mj/repos/xtalk/node_modules/miniflare/dist/src/index.js:6292:36)
at Proxy.fetch (file:///Users/mj/repos/xtalk/node_modules/miniflare/dist/src/index.js:6280:34)
at GET (webpack-internal:///(rsc)/./app/ws/route.ts:14:33)
...
```
This issue seems very similar to https://github.com/cloudflare/miniflare/issues/454 however I'm on wrangler `3`. After tracing it through in the debugger:
```javascript
> typeof V
'object'
> V instanceof Request
false
> V.url
'http://localhost:3000/ws'
> V.constructor.name
'bound NextRequestHint'
```
### Expected behavior
The request to be successfully passed to the DO.
### Steps to reproduce
Follow [next-on-pages dev guide](https://github.com/cloudflare/next-on-pages/tree/main/internal-packages/next-dev) to setup a dummy DO and observe the error.
Contributor guide
Assessment
This issue has not been assessed yet.