Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: SvelteKit Still Had Null Body Response Error #394

Closed
DevOfManyThings opened this issue Feb 5, 2022 · 9 comments 路 Fixed by #408
Closed

馃悰 BUG: SvelteKit Still Had Null Body Response Error #394

DevOfManyThings opened this issue Feb 5, 2022 · 9 comments 路 Fixed by #408
Labels
pages Relating to Pages

Comments

@DevOfManyThings
Copy link

What version of Wrangler are you using?

0.0.15

What operating system are you using?

Windows

Describe the Bug

SvelteKit still gets null body response error which was fixed in https://github.com/cloudflare/miniflare/releases/tag/v2.0.0-rc.3, not sure how Wrangler2 incorporates miniflare, is there a pending version update or is this a separate issue?

SETUP

npm init svelte@next my-app
npm i --save-dev @sveltejs/adapter-cloudflare@next
Update svelte.config.js to use adapter.
npm install

LAUNCH
npx wrangler pages dev --proxy 3000 -- npx svelte-kit dev --host
ERROR
When viewing project on http://localhost:8788/ page will alternate between rendering correctly and showing this:
image

BEHAVIOR
When viewing same page with network tab open and disable cache enabled, error does not occur

Output:

[pages:err] GET /: TypeError: Response with null body status cannot have body
    at new Response (E:\Programming\Projects\ArtPageSvelteWrangler\node_modules\undici\lib\fetch\response.js:160:15)
    at new Response (E:\Programming\Projects\ArtPageSvelteWrangler\node_modules\@miniflare\core\src\standards\http.ts:556:13)
    at Object.construct (E:\Programming\Projects\ArtPageSvelteWrangler\node_modules\@miniflare\core\src\plugins\core.ts:69:29)
    at Object.fetch (<script>:5:24)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at EventTarget.[kDispatchFetch] (E:\Programming\Projects\ArtPageSvelteWrangler\node_modules\@miniflare\core\src\standards\event.ts:359:13)
    at Server.<anonymous> (E:\Programming\Projects\ArtPageSvelteWrangler\node_modules\@miniflare\http-server\src\index.ts:167:20)
GET / 500 Internal Server Error (22.61ms)
@threepointone
Copy link
Contributor

Thank you for reporting this, and sorry for the trouble! Could you try this with wrangler@alpha? There's a small chance we've already fixed this, but I'm not sure atm.

@DevOfManyThings
Copy link
Author

No trouble at all! All comes with the fun of using new things eh?

Wrangler was updated to 0.0.0-536c7e5 and issue still occurs with same behaviour as above.

@Electroid Electroid added the pages Relating to Pages label Feb 5, 2022
@threepointone
Copy link
Contributor

Well damn. Alright, we'll figure this out. Thanks again for the report!

@GregBrimble
Copy link
Member

Don't know where it is, but this is because somewhere (either in wrangler or in SvelteKit), a Response is being constructed incorrectly.

I've made the mistake myself several times before (usually when cloning an existing Response). This is what you need to do.

@GregBrimble
Copy link
Member

Completely untested, but looks like it might be this line in SvelteKit: https://github.com/sveltejs/kit/blob/master/packages/adapter-cloudflare/files/worker.js#L17

@petebacondarwin
Copy link
Contributor

petebacondarwin commented Feb 5, 2022

Had a quick look at this. It seems that the Worker is returning a 304 - Unmodified response that also has a body, which undici is then complaining about. It might have been that this was always the case (?) but we were using a http client that didn't complain about this?

@petebacondarwin
Copy link
Contributor

@GregBrimble - I tried changing that line but still got the error.

From what I can make out it is miniflare that is dispatching the response, but I guess that is just being proxied from svelte?

@petebacondarwin
Copy link
Contributor

We've found the issue. The problem is in the Miniflare proxy. @GregBrimble is working on a fix. In the meantime, you can (sort of) workaround this by building the Svelte app and then running the build output via pages directly...

npm run build
npx wrangler pages dev .svelte-kit/cloudflare

@petebacondarwin
Copy link
Contributor

Fix here: cloudflare/miniflare#172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pages Relating to Pages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants