kit: adapter-static can't build initial project

Describe the bug

Current version of adapter-static broken from 1.0.0-next.24 version After that update adapter-static failing to build Kit template. Current Skeleton App not compatible with svelte kit, or svelte kit is not compatible with static adapter.

Reproduction

Create new kit project (npm init svelte@next my-app) install @sveltejs/adapter-static@next Add it to svelte.config.js as adapter instead of adapter-auto. Try to build app.

Logs

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-static
> body used already for: 
    at consumeBody (file:///C:/proj/staticAdapterBroken/node_modules/@sveltejs/kit/dist/install-fetch.js:
4912:9)
    at Response.text (file:///C:/proj/staticAdapterBroken/node_modules/@sveltejs/kit/dist/install-fetch.j
s:4877:24)
    at visit (file:///C:/proj/staticAdapterBroken/node_modules/@sveltejs/kit/dist/chunks/index5.js:483:39
)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
    Memory: 13.38 GB / 31.88 GB
  Binaries:
    Node: 16.9.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.15 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.22.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.62)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.14
    @sveltejs/adapter-static: ^1.0.0-next.26 => 1.0.0-next.26
    @sveltejs/kit: next => 1.0.0-next.236
    svelte: ^3.44.0 => 3.46.2

Severity

blocking all usage of SvelteKit

Additional Information

Actually I was trying to fix https://github.com/MailCheck-co/mailcheck.site/commit/abecae86f209ffc9abdae02d59611bb406235472, but during debug I disabled everything in project with no luck. Then I tried to create new project, and found that new projects are broken from start.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 17
  • Comments: 24 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I don’t fully understand how this is happening but I’ve narrowed it down. Basically, node-fetch doesn’t allow you to “consume” a response body more than once, i.e. you can’t call await response.text() more than once on the same response. That’s the immediate cause of the error.

It happens in prerender’s visit() method. It calls app.render() which populates the dependencies Map. The values of the map are Response objects. The body of these Response objects is consumed in load_node here. Then, when visit() iterates through the dependencies, it tries to consume the body again here. This fails for the reason described above.

I’m not sure what the right fix would be here because I don’t understand the code well enough but I’m pretty sure this is the source of the error.

Facing the same problem with my own SvelteKit project, I also noticed that the default project doesn’t build. It was a bit tricky to see which release introduced this bug, but from my experiments it looks like builds start to fail from @sveltejs/kit@^1.0.0-next.234 (although that fails with a different error request in handle has been replaced with event).

I arrived at this conclusion by doing the following (which might not be the correct approach…) npm init svelte@2.0.0-next.94 my-app, cd my-app, and npm install npm i -D @sveltejs/adapter-static@next and set adapter-static in svelte.config.js (fails) npm install -D @sveltejs/kit@1.0.0-next.233 (builds) npm install -D @sveltejs/kit@1.0.0-next.234 (fails)

Same issue for me 😕

This problem still exists with @sveltejs/kit@1.0.0-next.305

Reproducible on my end with demo app + adapter-static. According to https://github.com/node-fetch/node-fetch/issues/533#issuecomment-429261523, perhaps we can use .clone() internally for the prerenderer. The issue likely came up when we switch to using the Response object.

I’m finding a similar issue (though my build is failing silently, not generating the index.html file in build folder). I pinned static-adapter on 1.0.0-next.26, and tried rolling back kit versions and building until it worked. For me, 1.0.0-next.231 is where it stops working.