Skip to content

SvelteKit v1.0.0-next.304 is suddenly executing code during build, prerender problem?Β #4492

Closed

Description

@bluepuma77

Describe the bug

I am building a full stack SvelteKit adapter-node application with database connection. It is build in a container to be run in a container. Todays npm update killed my build process because npm run build started to execute my source code.

So far this would build, but with SvelteKit v1.0.0-next.304 (and its dependencies) build started to fail:

// hooks.ts
export const handle = async ({ event, resolve }) => {
	// simulate crash because DB can not be connected 
        // without credentials and access during build process
	console.log('Going to simulate crash')
	process.exit();

	const response = await resolve(event);
	return response;
};

My last good npm update was 3 days ago.

Note: The build process always worked, but I had to use npm ci --production --ignore-scripts later with the built code.

This may have to do with the pre-rendering, but I have not touched those settings.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-9crzvj?file=src%2Fhooks.js

const config = {
	kit: {
		prerender: {
			enabled: false
		}
	}
}

Run npm run build and it will execute the code and exit the process

Logs

No response

System Info

WORKS

  System:
    OS: macOS 12.2.1
    CPU: (8) arm64 Apple M1
    Memory: 105.05 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.19.0 - /opt/homebrew/opt/node@14/bin/node
    npm: 6.14.16 - /opt/homebrew/opt/node@14/bin/npm
  Browsers:
    Chrome: 100.0.4896.60
    Firefox: 98.0.2
    Safari: 15.3
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0-next.33 => 1.0.0-next.33
    @sveltejs/adapter-node: ^1.0.0-next.73 => 1.0.0-next.73
    @sveltejs/kit: ^1.0.0-next.303 => 1.0.0-next.303
    svelte: ^3.46.0 => 3.46.4

WORKS NOT ANYMORE

  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0-next.34 => 1.0.0-next.34
    @sveltejs/adapter-node: ^1.0.0-next.73 => 1.0.0-next.73
    @sveltejs/kit: ^1.0.0-next.304 => 1.0.0-next.304
    svelte: ^3.46.6 => 3.46.6

Severity

blocking an upgrade

Additional Information

No response

Activity

  1. bluepuma77 commented on Apr 1, 2022

    @bluepuma77
    Author

    Setting full

    prerender: {
    	enabled: false,
    	default: false,
    	onError: 'continue',
    },
    

    does not help

  2. mrkishi commented on Apr 1, 2022

    @mrkishi
    Member

    Likely to have been introduced by #4443, since now we try creating a fallback regardless of prerender settings.

    I'm not sure how we want to deal with it, though.

  3. added
    bug
    p1-important
    on Apr 1, 2022
  4. bluepuma77 commented on Apr 2, 2022

    @bluepuma77
    Author
  5. aradalvand commented on Apr 2, 2022

    @aradalvand
  6. dimfeld commented on Apr 3, 2022

    @dimfeld
    Contributor

    Why would you pre-render when prerendering.enabled = false? #4443 makes no sense to me.

    Because we still need a fallback file when using the static adapter with prerendering disabled, otherwise you don't get a usable app at all. Perhaps the fallback file generation needs to be separated from the prerender process.

  7. ximus commented on Apr 3, 2022

    @ximus
  8. bluepuma77 commented on Apr 3, 2022

    @bluepuma77
    Author

    @dimfeld So the solution would be to only ignore prerendering.enabled = false when using adapter-static.

    Because it seems wrong for all the other adapters. We could completely remove prerendering.enabled.

  9. aradalvand commented on Apr 3, 2022

    @aradalvand
  10. ponderingexistence commented on Apr 3, 2022

    @ponderingexistence
  11. ponderingexistence commented on Apr 3, 2022

    @ponderingexistence

    By the way, I think the p0-urgent label is more appropriate for this.
    It's breaking a lot of people's stuff.

  12. aahmadi458 commented on Apr 3, 2022

    @aahmadi458
  13. dimfeld commented on Apr 3, 2022

    @dimfeld
    Contributor

    If you read the second line of my comment I suggested that the fallback file generation be separated out. The way it works right now they’re very closely intertwined for reasons that I’m not sure of but probably just never mattered before the pretender process was moved into the build step.

    Everyone lets all calm down please. It’s not like we’re out here trying to break things for you. I wasn’t freaking out on here when my build broke due to the earlier pre-rendering change. Instead I pinned my version to a working one and helped to figure out a solution. You would be good to do the same.

    Just pin your version to 303 for now and we can all get this fixed in a calm manner.

  14. mrkishi commented on Apr 3, 2022

    @mrkishi
    Member

    Bugs eventually squeeze in unnoticed, and being on the @next edge of a fast-changing prerelease library means you'll eventually hit them. We welcome collaboration on getting things fixed, but pointing out how obvious a bug is from your perspective doesn't help anyone.

    I'm bumping this to p0-urgent, but please let's strive to keep the discussion constructiveβ€”adding a thumbs up to the issue is enough to signal you were (unfortunately) affected by it.

  15. 13 remaining items

  16. dimfeld commented on Apr 10, 2022

    @dimfeld
    Contributor
  17. PH4NTOMiki commented on Apr 10, 2022

    @PH4NTOMiki
    Contributor

    No you don't, and you don't understand how fallback is generated. I know it doesn't contain layout or page, but it DOES contain <script> tag with start function invocation, and one of the parameters of that function is session and that parameter gets filled out by getSession hook in here

    session: ${try_serialize($session, (error) => {
    throw new Error(`Failed to serialize session data: ${error.message}`);
    })},
    either way(fallback or not, that needs to get filled out to be able to start SvelteKit client app)

  18. PH4NTOMiki commented on Apr 10, 2022

    @PH4NTOMiki
    Contributor

    For fallback its here

    if (state.prerender && state.prerender.fallback) {
    return await render_response({
    event,
    options,
    state,
    $session: await options.hooks.getSession(event),

  19. dimfeld commented on Apr 10, 2022

    @dimfeld
    Contributor
  20. PH4NTOMiki commented on Apr 10, 2022

    @PH4NTOMiki
    Contributor

    No worries, I reacted a bit harsh too.

  21. dimfeld commented on Apr 11, 2022

    @dimfeld
    Contributor

    So at this point I think that the following changes should be sufficient:

    • Revert the previous PR that changed the fallback render behavior
    • Mention in the SPA Mode section of the adapter-static docs that setting prerender.entries: [] can help if Node.js throws errors when importing your page/layout components.

    If I have some time tonight I'll try to get a PR together for this.

  22. added a commit that references this issue on Apr 13, 2022
    f725488
  23. added a commit that references this issue on Apr 13, 2022
    fc6d9f9
  24. added a commit that references this issue on Apr 13, 2022
    21d20c3
  25. ximus commented on Apr 14, 2022

    @ximus
    Contributor

    thanks @dimfeld for carrying this through

  26. jerrygreen commented on Aug 15, 2022

    @jerrygreen

    When setting prerender.entries: [] in config, it helps to skip the problem, but then the whole sense of adapter-static is lost, it seems... At least, upon building with prerender.entries: [], I'm not seeing all my static pages in build folder, and say... Can't use it for Github Pages.

    Maybe there's actual solution, rather than skipping the problem?

    P.S. I used the most currently recent "@sveltejs/kit": "1.0.0-next.405" and "@sveltejs/adapter-static": "1.0.0-next.39".

  27. Rich-Harris commented on Nov 18, 2022

    @Rich-Harris
    Member

    hey all β€” flagging this discussion, as people here might have thoughts on it: #7716

  28. removed
    bug
    on Aug 4, 2026
  29. added theissue type on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p0-urgent

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions