kit icon indicating copy to clipboard operation
kit copied to clipboard

Miniflare error fetching immutable assets

Open dorianim opened this issue 2 years ago • 3 comments

Describe the bug

When running svelte-kit on Cloudflare or Miniflare, no assets in /_app/immutable can be fetched with the error TypeError: Cannot read properties of undefined (reading 'fetch'). I have no idea what causes this.

Reproduction

  • create a new svelte-kit project npm create svelte@latest
  • install adapter-cloudflare: npm i --safe-dev @sveltejs/adapter-cloudflare
  • change import to adapter-cloudflare in svelte.config.js
  • install miniflare npm i --save-dev miniflare
  • build and run with miniflare: npm run build && npx miniflare --debug --modules .svelte-kit/cloudflare/_worker.js
  • open http://127.0.0.1:8787/
  • error appears in console
  • open http://127.0.0.1:8787/_app/immutable/start-49f8c643.js
  • error appears in browser

Logs

[mf:inf] Listening on :8787
[mf:inf] - http://127.0.0.1:8787
[mf:inf] - http://10.37.91.138:8787
[mf:inf] - http://10.10.0.97:8787
[mf:inf] - http://10.1.1.34:8787
[mf:inf] Updated `Request.cf` object cache!
GET / 200 OK (43.86ms)
[mf:err] GET /_app/immutable/start-49f8c643.js: TypeError: Cannot read properties of undefined (reading 'fetch')
    at Object.fetch (/home/dorian/Documents/Programmieren/svelte-kit/test/.svelte-kit/cloudflare-tmp/_worker.js:51:30)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at EventTarget.[kDispatchFetch] (/home/dorian/Documents/Programmieren/svelte-kit/test/node_modules/@miniflare/core/src/standards/event.ts:385:13)
    at Server.<anonymous> (/home/dorian/Documents/Programmieren/svelte-kit/test/node_modules/@miniflare/http-server/src/index.ts:298:20)
GET /_app/immutable/start-49f8c643.js 500 Internal Server Error (344.28ms)


### System Info

```Shell
System:
    OS: Linux 5.15 Archcraft
    CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
    Memory: 4.36 GB / 15.41 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 16.18.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.2 - /usr/bin/npm
  Browsers:
    Chromium: 108.0.5359.124
    Firefox: 108.0
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.0 
    @sveltejs/adapter-cloudflare: ^1.0.0 => 1.0.0 
    @sveltejs/kit: ^1.0.0 => 1.0.0 
    svelte: ^3.54.0 => 3.55.0 
    vite: ^4.0.0 => 4.0.1

Severity

blocking all usage of SvelteKit

Additional Information

No response

dorianim avatar Dec 14 '22 22:12 dorianim

Does it work when you deploy to actual cloudflare workers - in other words, is this "just" an issue when using miniflare locally?

dummdidumm avatar Dec 15 '22 09:12 dummdidumm

Sometimes. I have a seemingly similar issue with the actual Cloudflare worker, but I am not really able to troubleshoot it, since Cloudflare doesn't provide any logs and I can't test it locally because of this issue 😅

So it would be great to get the miniflare fixed to make the troubleshooting on the actual Cloudflare worker easier :)

Edit: I did some digging, and the error on Cloudflare is probably related to something else.

dorianim avatar Dec 15 '22 11:12 dorianim

I can reproduce this, though I'm not sure what we can do about it to solve it. Miniflare doesn't provide the required ASSETS durable object. I don't cloudflare enough to know how to provide, or if wrangler should be used instead.

Giving this the documentation label in case someone solves this riddle so that we can add this to the README

dummdidumm avatar Jan 11 '23 10:01 dummdidumm

From the Miniflare docs:

Cloudflare Pages are not directly supported by Miniflare. You must use Wrangler 2.

Unfortunately I don't think there's anything we can do to fix this unless and until Miniflare supports Pages.

Rich-Harris avatar Mar 02 '23 20:03 Rich-Harris