admin管理员组文章数量:1327843
I have a SvelteKit application, just following the example from the docs /tutorial/named-form-actions, the problem is that everything works until I try to write an action:
at: +page.server.js
export const actions = {
default: async () => {
console.log('test')
}
};
vite immediately fails with: "Cannot prerender pages with actions"
Error: Cannot prerender pages with actions
at render_page (file:///mydir/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:87:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async resolve (file:///mydir/node_modules/@sveltejs/kit/src/runtime/server/index.js:356:17)
at async respond (file:///mydir/node_modules/@sveltejs/kit/src/runtime/server/index.js:229:20)
at async file:///mydir/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:444:22
Probably I'm missing some configuration or forgot some basics, any idea?
I have a SvelteKit application, just following the example from the docs https://learn.svelte.dev/tutorial/named-form-actions, the problem is that everything works until I try to write an action:
at: +page.server.js
export const actions = {
default: async () => {
console.log('test')
}
};
vite immediately fails with: "Cannot prerender pages with actions"
Error: Cannot prerender pages with actions
at render_page (file:///mydir/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:87:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async resolve (file:///mydir/node_modules/@sveltejs/kit/src/runtime/server/index.js:356:17)
at async respond (file:///mydir/node_modules/@sveltejs/kit/src/runtime/server/index.js:229:20)
at async file:///mydir/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:444:22
Probably I'm missing some configuration or forgot some basics, any idea?
Share Improve this question edited Feb 4, 2023 at 10:53 Gudarzi 5753 gold badges8 silver badges26 bronze badges asked Jan 8, 2023 at 1:06 Ziur OlpaZiur Olpa 2,1332 gold badges17 silver badges33 bronze badges1 Answer
Reset to default 8The docs simply state:
Pages with actions cannot be prerendered, because a server must be able to handle the action POST requests.
The assumption is probably that a form action should have an effect on the page when submitted, which would not be possible when a static HTML page is served every time.
You could try to separate any logic to an API endpoint that is not associated with your prerendered page. It depends on what you are trying to do here, maybe the page should simply not be prerendered at all.
This means that +page.ts
should set:
export const prerender = false;
版权声明:本文标题:javascript - Why actions in SveltKit give "Error: Cannot prerender pages with actions"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742219711a2435224.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论