question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Not found: /__data.json` when use form actions with `use:enhance`

See original GitHub issue

Describe the bug

I have this code:

<!-- routes/+page.svelte -->

<script>
	import { enhance } from '$app/forms';
</script>

<form method="POST" use:enhance>
	<input type="text" name="text" id="textid" />
	<button type="submit">submit</button>
</form>
// routes/+page.server.js

export const actions = {
	default: () => {
		return {
			success: true
		};
	}
};

when I submit the form, the following error occurs:

Not found: /__data.json
Error: Not found: /__data.json
    at resolve (file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/runtime/server/index.js:264:13)
    at resolve (file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/runtime/server/index.js:295:5)
    at Object.handle (file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:343:66)
    at respond (file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/runtime/server/index.js:292:40)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:413:22

exactly the same happens if they are named actions, when using use:enhance I get the same error. I thought it was related to #7410, but I updated to the latest version and the error described still occurs

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-kbaf32?file=src/routes/+page.svelte

other option (local)

npm create svelte@latest 
// zero configuration
add files /+page.svelte and /+page.server.js

Logs

Not found: /__data.json
Error: Not found: /__data.json
    at resolve (file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/runtime/server/index.js:264:13)
    at resolve (file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/runtime/server/index.js:295:5)
    at Object.handle (file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:343:66)
    at respond (file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/runtime/server/index.js:292:40)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///C:/Users/dange/Documents/dev/sveltekit/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:413:22

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 AMD Ryzen 9 5900HS with Radeon Graphics
    Memory: 8.55 GB / 15.41 GB
  Binaries:
    Node: 18.0.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.755.0), Chromium (107.0.1418.24), ChromiumDev ((@(&"C:/Users/dange/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe" init pwsh --config="C:\Users\dange\AppData\Local\Programs\oh-my-posh\themes\jandedobbeleer.omp.json" --print) -join "`n") | Invoke-Expression)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.85
    @sveltejs/kit: next => 1.0.0-next.528
    svelte: ^3.44.0 => 3.52.0
    vite: ^3.1.0 => 3.2.1

Severity

blocking all usage of SvelteKit

Additional Information

I can do a minimal reproduction, but I literally just start a new project and try to use form actions with use:enhance

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:8
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
KarolusDcommented, Oct 30, 2022

Same here, reverting back to: “@sveltejs/kit”: “1.0.0-next.527” helps.

1reaction
boian-ivanovcommented, Oct 29, 2022

I’ve just about wanted to report this issue. I’ve been getting it on the root route +page.server.js/ts file, but I’ve been able to also replicate it with the default create-svelte app. Stackblitz link here. In my experience if you have a +page.server.js/ts in the root of the routes, the /__data.json won’t exist so it can’t fetch any of the data that you are trying to pass at prerender. On full page load it works, but on prerender it doesn’t. Seems like quite the braking issue.

Edit: This issue seems to only exists on server only routes. If you make the +page.server.js/ts to a +page.js/ts this doesn’t seem to happen. But obviously you may need some API data on root that may require secret API keys.

Edit 2: as a momentary fix, I’ve been able to downgrade to 527 and the issue doesn’t appear anymore. So I assume that it comes from the changes in this commit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Form actions • Docs • SvelteKit
Form actions are the preferred way to send data to the server, since they can be progressively enhanced, but you can also use...
Read more >
After clicking Submit button it takes me to store-json but ...
After clicking Submit button it takes me to store-json but showing 404 not found ; namespace App\Http ; Controllers; use Redirect ; Response;...
Read more >
Sveltekit Changes: Form Actions and Progressive Enhancement
Introduction. In this article we gonna learn and talk about SvelteKit form progressive enhancement use action and new form actions.
Read more >
Svelte Kit Form Actions 101 - New Svelte Kit API - YouTube
Become a Level Up Pro and take your web skills to the next level!https://www.leveluptutorials.comThe best web development podcast out ...
Read more >
SvelteKit SSR forms explained - codechips
First, if you use SSR it means the app needs some kind of server to render the pages, serverless or not. This can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found