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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapter-static can't build initial project #3473

Closed
nosovk opened this issue Jan 20, 2022 · 24 comments · Fixed by #3521
Closed

adapter-static can't build initial project #3473

nosovk opened this issue Jan 20, 2022 · 24 comments · Fixed by #3521
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-static

Comments

@nosovk
Copy link
Contributor

nosovk commented Jan 20, 2022

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 MailCheck-co/mailcheck.site@abecae8, 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.

@nosovk
Copy link
Contributor Author

nosovk commented Jan 21, 2022

@vycke
Copy link

vycke commented Jan 21, 2022

Can conform this is happening for me as well. Dependencies from my package.json: "@sveltejs/adapter-static": "^1.0.0-next.24", "@sveltejs/kit": "^1.0.0-next.236".

@dwsmart
Copy link
Contributor

dwsmart commented Jan 21, 2022

also happens with "@sveltejs/adapter-node": "^1.0.0-next.66" if you set

<script context="module">
	export const prerender = true;
	…
</script>

on a routes/ svelte file if there's also a export const load = async ({ fetch }) => {

@vycke
Copy link

vycke commented Jan 21, 2022

For the static-adapter I've tested it by removing the export const prerender = true and export const hydrate = false (which were both existing in my project). This does not solve the issues though.

@jormaj
Copy link

jormaj commented Jan 21, 2022

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 [email protected] 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/[email protected] (builds)
npm install -D @sveltejs/[email protected] (fails)

@russellsamora
Copy link

russellsamora commented Jan 21, 2022

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.

@kamholz
Copy link

kamholz commented Jan 22, 2022

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.

@nusendra
Copy link

got this problem too

@nosovk
Copy link
Contributor Author

nosovk commented Jan 22, 2022

Unfortunately, I have no clue how to fix it now :(
Also, I can't understand how tests passed on main branch if it's broken. Probably problem in current version of template (which differs from one used in tests)

@eba8
Copy link

eba8 commented Jan 23, 2022

I'm facing this problem too - it's been an absolute nightmare.
Does anybody know if the team is working on a fix for this?

@bluwy bluwy added bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-static labels Jan 23, 2022
@bluwy
Copy link
Member

bluwy commented Jan 23, 2022

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

@moritzebeling
Copy link

moritzebeling commented Jan 24, 2022

The body used already for error also happens with the adapter-netlify. As a temporary fix, you can remove export const prerender = true, which leads to a successful build in my case... but of course also means that none of the pages are being prerendered...

SvelteKit 1.0.0-next.240
Netlify Adapter 1.0.0-next.42

@pavelloz
Copy link

I just got this error as well.

  npmPackages:
    @sveltejs/adapter-static: next => 1.0.0-next.26 
    @sveltejs/kit: next => 1.0.0-next.241 

I dont know if it helps but before svelte build there is this message:

17:07:24 [vite-plugin-svelte] vite-plugin-svelte was unable to find package.json of the following packages and wasn't able to resolve via their "svelte" field.
If you had difficulties importing svelte components from a package, then please contact the author and ask them to export the package.json file.
- fs

I would contact the author of fs module but i have a weird feeling they wont be interested in my issue :-)

@swyxio
Copy link
Contributor

swyxio commented Jan 25, 2022

confirmed @russellgoldenberg's observation that pinning dependency to npm i -D @sveltejs/[email protected] worked.

@eba8
Copy link

eba8 commented Jan 25, 2022

Just tried rolling back versions and it looks like it doesn't work on my end. Tried going back a few months.

Also tried commenting out export const prerender = true and that didn't help either.

@pavelloz
Copy link

pavelloz commented Jan 25, 2022

@eba8 when you downgrade version remember also to clean npm cache (npm cache clean --force) and also write version explicitly in package.json. I got stuck for a while on this process because i forgot about the npm cache one day.

@skoontastic
Copy link

Just ran into this and did what @sw-yx and @pavelloz suggested, and it worked.

@eba8
Copy link

eba8 commented Jan 25, 2022

Maybe I'm doing this wrong?

I've updated package.json with @sveltejs/adapter-static": "^1.0.0-next.24 and @sveltejs/kit": "^1.0.0-next.231.

Deleted svelte-kit files, build and node modules.

Ran npm cache clean --force

did npm install

npm run build

The error I still get: body used already for

@eba8
Copy link

eba8 commented Jan 25, 2022

With the help of my amazing friend @octokatherine it's now working.

My mistake was having ^ in the versions.

Package.json with @sveltejs/adapter-static": "1.0.0-next.24 and @sveltejs/kit": "1.0.0-next.231 works

@pavelloz
Copy link

Ah yes, the dirty ^ :-) Its not really freezing if its ^ :-)

Rich-Harris added a commit that referenced this issue Jan 26, 2022
…3521)

* Add failing test for #3473 prerender error body used already

* Fix reading from same response body twice during prerender

* Fix quotes

* Add changeset

* Fix casing for internal variables

* Revert change of cloning response as bug was actually in prerender.js

* Avoid reading response body twice

* Revert "Avoid reading response body twice"

This reverts commit cecf7dd.

Revert being stupid #1

* Revert "Revert change of cloning response as bug was actually in prerender.js"

This reverts commit 5e5f30b.

Revert being stupid #2

* store buffered depenedency bodies for prerendering

* failing test for non-buffered endpoint data

* use buffered body if available, otherwise buffer

Co-authored-by: Rich Harris <[email protected]>
indaco added a commit to sveltinio/sveltin that referenced this issue Jan 27, 2022
…already_' error building the project removed

SvelteKit 1.0.0-next.244 fixed [#3473](sveltejs/kit#3473) and [#3521](sveltejs/kit#3521). `clone()` on fetch response as workaround to avoid '_body used already_' error when building the project removed
@vibhanshu909
Copy link

I'm using adapter-auto.
Started getting this error from today on the release of 1.0.0-next.292.
Using version 1.0.0-next.291 fixes this problem for me.

@24jr
Copy link

24jr commented Mar 22, 2022

I'm having this problem right now. No index.html file is created in build folder using adapter-static 1.0.0-next.29 and svelte/kit next. Using versions @eba8 mentioned works but would like to use latest version.

Is this bug and something that will be fixed or a new way of doing things. Causes my aws-amplify build to fail and caused capacitor build to fail

@iocron
Copy link

iocron commented Apr 4, 2022

This problem still exists with @sveltejs/[email protected]

@yuliankarapetkov
Copy link

Same issue for me 😕

sitek94 added a commit to sitek94/strong-charts that referenced this issue Apr 9, 2022
sitek94 added a commit to sitek94/strong-charts that referenced this issue Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-static
Projects
None yet
Development

Successfully merging a pull request may close this issue.