Skip to content

Problem in static site (ssr=false, prerender=true) after upgrade to 1.27.5 #11031

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

Closed
ff-ils opened this issue Nov 13, 2023 · 0 comments · Fixed by #11032
Closed

Problem in static site (ssr=false, prerender=true) after upgrade to 1.27.5 #11031

ff-ils opened this issue Nov 13, 2023 · 0 comments · Fixed by #11032
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.

Comments

@ff-ils
Copy link

ff-ils commented Nov 13, 2023

Describe the bug

It seems that fix #10988 breaks imports and libraries which use browser objects. The example provided is self contained, but the problem happens also when including external libraries, on which there is no control.
The problem is not present using version 1.27.3

Reproduction

This repo contains a simple example https://github.com/ff-ils/ssr-prerender

Logs

npm run build

> [email protected] build
> vite build


vite v4.5.0 building SSR bundle for production...
✓ 74 modules transformed.

vite v4.5.0 building for production...
✓ 63 modules transformed.
.svelte-kit/output/client/_app/version.json                              0.03 kB │ gzip: 0.05 kB
.svelte-kit/output/client/.vite/manifest.json                            2.12 kB │ gzip: 0.40 kB
.svelte-kit/output/client/_app/immutable/nodes/2.cde87348.js             0.43 kB │ gzip: 0.30 kB
.svelte-kit/output/client/_app/immutable/nodes/0.f700f867.js             0.74 kB │ gzip: 0.48 kB
.svelte-kit/output/client/_app/immutable/nodes/1.b30bcfe0.js             1.03 kB │ gzip: 0.60 kB
.svelte-kit/output/client/_app/immutable/chunks/scheduler.e108d1fd.js    2.16 kB │ gzip: 1.02 kB
.svelte-kit/output/client/_app/immutable/chunks/singletons.94c07e86.js   2.85 kB │ gzip: 1.46 kB
.svelte-kit/output/client/_app/immutable/chunks/index.79a65843.js        5.40 kB │ gzip: 2.30 kB
.svelte-kit/output/client/_app/immutable/entry/app.0fc24b8e.js           5.84 kB │ gzip: 2.32 kB
.svelte-kit/output/client/_app/immutable/entry/start.5c119207.js        24.89 kB │ gzip: 9.80 kB
✓ built in 308ms
ReferenceError: window is not defined
    at file:///C:/Test/ssr-prerender/.svelte-kit/output/server/entries/pages/_page.svelte.js:3:11
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async Module.component (file:///C:/Test/ssr-prerender/.svelte-kit/output/server/nodes/2.js:5:59)
    at async Promise.all (index 1)
    at async render_response (file:///C:/Test/ssr-prerender/.svelte-kit/output/server/index.js:1369:21)
    at async render_page (file:///C:/Test/ssr-prerender/.svelte-kit/output/server/index.js:2209:12)
    at async resolve (file:///C:/Test/ssr-prerender/.svelte-kit/output/server/index.js:2790:24)
    at async respond (file:///C:/Test/ssr-prerender/.svelte-kit/output/server/index.js:2676:22)
    at async visit (file:///C:/Test/ssr-prerender/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:203:20)

node:internal/event_target:1083
  process.nextTick(() => { throw err; });
                           ^
Error: 500 /
To suppress or handle this error, implement `handleHttpError` in https://kit.svelte.dev/docs/configuration#prerender
    at file:///C:/Test/ssr-prerender/node_modules/@sveltejs/kit/src/core/config/options.js:212:13
    at file:///C:/Test/ssr-prerender/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:64:25
    at save (file:///C:/Test/ssr-prerender/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:403:4)
    at visit (file:///C:/Test/ssr-prerender/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:236:3)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

Node.js v20.9.0

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700
    Memory: 10.13 GB / 31.68 GB
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.0.0 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Spartan (44.19041.3570.0), Chromium (119.0.2151.58)
    Internet Explorer: 11.0.19041.3570
  npmPackages:
    @sveltejs/adapter-static: 2.0.3 => 2.0.3
    @sveltejs/kit: 1.27.4 => 1.27.4
    svelte: 4.2.3 => 4.2.3
    vite: 4.5.0 => 4.5.0

Severity

blocking an upgrade

Additional Information

No response

@eltigerchino eltigerchino added the bug Something isn't working label Nov 13, 2023
@eltigerchino eltigerchino added the p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. label Nov 13, 2023
dummdidumm pushed a commit that referenced this issue Nov 14, 2023
fixes #11031

#10988 introduced a regression where the response during prerendering would always have SSR enabled. This PR fixes this by setting it according to the SSR page option.
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants