N
Nuxtβ€’2y ago
Rowin

[nuxt] Cannot load payload /_payload.json

I just created a brand new Nuxt project using npx nuxi@latest init. I set up routing by adding <NuxtPage /> to app.vue and creating pages/index.vue. Then I made a static export using npm run generate and finally I serve it using npx serve .output/public. I am getting the following error in my browser's console:
[nuxt] Cannot load payload /hello/_payload.json SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
[nuxt] Cannot load payload /hello/_payload.json SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Why is Nuxt is trying to load a non-existent JSON file? Did I find a bug already? 😬
10 Replies
Rowin
RowinOPβ€’2y ago
Works fine using Nuxt 3.6.1. Possibly related to this: https://github.com/nuxt/nuxt/pull/21860
GitHub
fix(nuxt): ensure static presets equivalent to nuxi generate by d...
πŸ”— Linked issue resolves #21254 ❓ Type of change πŸ“– Documentation (updates to the documentation or readme) 🐞 Bug fix (a non-breaking change that fixes an issue) πŸ‘Œ Enhancement (improving an existi...
Rowin
RowinOPβ€’2y ago
@danielroe ^ I am going to bed now so hopefully you don't mind me just tagging you instead of replying to the PR or making an issue πŸ˜…
Rowin
RowinOPβ€’2y ago
I was about to open an issue but someone else already did: https://github.com/nuxt/nuxt/issues/22068
GitHub
[nuxt] Cannot load payload /_payload.json Β· Issue #22068 Β· nuxt/nu...
Environment Operating System: Windows_NT Node Version: v18.16.0 Nuxt Version: 3.6.2 Nitro Version: 2.5.2 Package Manager: [email protected] Builder: vite User Config: pages, debug, dev, modules, pwa, app, ...
Rowin
RowinOPβ€’2y ago
@danielroe where does the payload come from if I set payloadExtraction to false? I noticed that no request is being made now if I browse to another page I am not using useFetch or anything like that so I suppose there shouldn't be a payload anyway but with payloadExtraction set to true it does generate one for every page I am not too familiar with Nuxt so if this makes no sense please let me know πŸ˜…
danielroe
danielroeβ€’2y ago
Nuxt saves the content of every useasyncdata/usefetch call in a payload when doing this, so they won't be refetched when client-side navigation. otherwise they will be refetched on client side navigation even though they won't on hard reloads
Rowin
RowinOPβ€’2y ago
I think I get it now. If payloadExtraction is set to false, the payload is only stored in the static HTML files (probably for hydrating?), and Nuxt just makes the API call when you navigate to another page. Did I get that right? And is it really necessary to generate a payload for pages that do not use useFetch or related? SvelteKit for example creates a __data.json (equivalent to Nuxt's _payload.json) only if you have a server-side load I also noticed that Nuxt does not prefetch the payload (like when you hover over a link for example), this would be a nice feature too SvelteKit has this: https://kit.svelte.dev/docs/link-options#data-sveltekit-preload-data
danielroe
danielroeβ€’2y ago
Exactly It should prefetch payloads on a generated site when they come into view
Rowin
RowinOPβ€’2y ago
Ah yes it does, my bad
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Rowin
RowinOPβ€’2y ago
Not sure what you mean
Want results from more Discord servers?
Add your server