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

Prerendered data.json on Vercel results in 500 error #8331

Closed
pawelblaszczyk5 opened this issue Jan 4, 2023 · 5 comments
Closed

Prerendered data.json on Vercel results in 500 error #8331

pawelblaszczyk5 opened this issue Jan 4, 2023 · 5 comments

Comments

@pawelblaszczyk5
Copy link
Contributor

pawelblaszczyk5 commented Jan 4, 2023

Describe the bug

Hello!

Currently prerendering (e.g. adapter static) with auto config for Vercel results with an error 500 on client-side navigations to pages with __data.json.

Few cents from things that I investigated (if I'm correct at least 😄). I checked and it correctly works in local build and preview mode. I think issue is with Vercel zero config mode for adapter static. Normally it outputs everything to build directory, for vercel it's creating a special directory. Wrote pages to ".vercel/output/static/_app/prerendered", then it creates a config which maps the underlying files to specific URLs e.g. {"src":"/en","dest":"_app/prerendered/en.html"}. The data.json prerendered files are missing from the generated Vercel config. Hence, they're matched based on filesystem and can't be found

Reproduction

Repo: https://github.com/pawelblaszczyk5/vercel-static-500
Deployed page: https://vercel-static-500.vercel.app/

Logs

Logs from browser:

test/__data.json?x-sveltekit-invalidated=_1:1          
Failed to load resource: the server responded with a status of 404 ()

start-28b3e5d3.js:1 
SyntaxError: Unexpected token 'T', "The page c"... is not valid JSON
handleError @ start-28b3e5d3.js:1

_________________________________________________

Response for data.json:

The page could not be found

NOT_FOUND

_________________________________________________

Build logs:

pawelblaszczyk@Pawes-MacBook-Pro vercel-static-500 % VERCEL=TRUE pnpm build

> vercel-static-500@0.0.1 build /Users/pawelblaszczyk/dev/vercel-static-500
> vite build


vite v4.0.4 building for production...
✓ 41 modules transformed.
12:18:12 [vite-plugin-svelte] dom compile done.
package                 files     time     avg
vercel-static-500           3   36.5ms  12.2ms
@sveltejs/kit               2   22.7ms  11.3ms

vite v4.0.4 building SSR bundle for production...
✓ 60 modules transformed.
12:18:12 [vite-plugin-svelte] ssr compile done.
package                 files    time     avg
vercel-static-500           5   9.7ms   1.9ms
Generated an empty chunk: "hooks".
.svelte-kit/output/server/vite-manifest.json                      1.88 kB
.svelte-kit/output/server/chunks/hooks.js                         0.00 kB
.svelte-kit/output/server/entries/pages/_layout.ts.js             0.05 kB
.svelte-kit/output/server/entries/pages/test/_page.server.ts.js   0.06 kB
.svelte-kit/output/server/entries/pages/_page.svelte.js           0.23 kB
.svelte-kit/output/server/entries/fallbacks/layout.svelte.js      0.24 kB
.svelte-kit/output/server/entries/pages/test/_page.svelte.js      0.37 kB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js       0.79 kB
.svelte-kit/output/server/chunks/index.js                         3.22 kB
.svelte-kit/output/server/index.js                               99.51 kB

Run npm run preview to preview your production build locally.
.svelte-kit/output/client/_app/version.json                                               0.03 kB
.svelte-kit/output/client/vite-manifest.json                                              3.61 kB
.svelte-kit/output/client/_app/immutable/modules/pages/_layout.ts-9cbb603b.js             0.07 kB │ gzip:  0.09 kB
.svelte-kit/output/client/_app/immutable/chunks/1-eb604b7f.js                             0.09 kB │ gzip:  0.10 kB
.svelte-kit/output/client/_app/immutable/chunks/2-f34ad418.js                             0.10 kB │ gzip:  0.10 kB
.svelte-kit/output/client/_app/immutable/chunks/3-e3c18f4a.js                             0.12 kB │ gzip:  0.12 kB
.svelte-kit/output/client/_app/immutable/chunks/_layout-da46b06b.js                       0.14 kB │ gzip:  0.14 kB
.svelte-kit/output/client/_app/immutable/chunks/0-4414e81b.js                             0.15 kB │ gzip:  0.13 kB
.svelte-kit/output/client/_app/immutable/components/pages/_page.svelte-360d4a1c.js        0.46 kB │ gzip:  0.32 kB
.svelte-kit/output/client/_app/immutable/components/layout.svelte-cd8f1078.js             0.54 kB │ gzip:  0.36 kB
.svelte-kit/output/client/_app/immutable/components/pages/test/_page.svelte-38bae22b.js   0.55 kB │ gzip:  0.39 kB
.svelte-kit/output/client/_app/immutable/components/error.svelte-03b3ffcb.js              0.98 kB │ gzip:  0.57 kB
.svelte-kit/output/client/_app/immutable/chunks/singletons-c1916556.js                    2.58 kB │ gzip:  1.34 kB
.svelte-kit/output/client/_app/immutable/chunks/index-7f3551f2.js                         6.87 kB │ gzip:  2.79 kB
.svelte-kit/output/client/_app/immutable/start-28b3e5d3.js                               26.63 kB │ gzip: 10.40 kB

> Using @sveltejs/adapter-static
  Wrote pages to ".vercel/output/static/_app/prerendered" and assets to ".vercel/output/static"done

_________________________________________________

Vercel config output: 

{"version":3,"routes":[{"src":"/_app/immutable/.+","headers":{"cache-control":"public, immutable, max-age=31536000"}},{"src":"/","dest":"_app/prerendered/index.html"},{"src":"/test","dest":"_app/prerendered/test.html"},{"src":"/test/","headers":{"location":"/test"},"status":308},{"handle":"filesystem"}]}

System Info

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 2.82 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - ~/.volta/tools/image/node/16.16.0/bin/node
    npm: 8.11.0 - ~/.volta/tools/image/node/16.16.0/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Safari: 16.2
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0 => 1.0.0 
    @sveltejs/kit: ^1.0.0 => 1.0.1 
    svelte: ^3.54.0 => 3.55.0 
    vite: ^4.0.0 => 4.0.4

Severity

serious, but I can work around it

Additional Information

I'll try to come up with PR with fix, however, I'm not really familiar with the codebase and adapters structure yet, so I'm not sure about my solution 😅
My stab at solving this: #8332

@elliott-with-the-longest-name-on-github
Copy link
Contributor

I'm a bit confused -- if you're deploying to Vercel, why not use the Vercel adapter?

@pawelblaszczyk5
Copy link
Contributor Author

Because, my whole site is prerenderable. The static adapter even has a special handling for Vercel with zero-config so I assume it's an intended use case. Anyway, it's exactly the same for adapter Vercel, you can check linked PR 😃

@ByteAtATime
Copy link

Oddly enough, this only happens during navigation and not when the page is directly loaded (from a direct link or reload)

@pawelblaszczyk5
Copy link
Contributor Author

Oddly enough, this only happens during navigation and not when the page is directly loaded (from a direct link or reload)

Yeah, because on direct navigation the data has been inlined during prerendering instead of fetched on demand

@pawelblaszczyk5
Copy link
Contributor Author

Resolved by linked PR, which has been merged and released, thank you 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants