hooks.js example causes a build error
See original GitHub issueDescribe the bug
When the following hooks.js
file exists, npm run build
throws an error. (However npm run dev
works without error and the site runs perfectly.)
To Reproduce
- Add
src/hooks.js
export async function handle(request, render) {
const response = await render(request);
return {
...response,
headers: {
...response.headers,
'x-custom-header': 'potato'
}
};
}
- Run
npm run build
.
The command will throw this error:
✓ 38 modules transformed.
.svelte/output/server/app.js 193.07kb
.svelte/output/server/style.css 7.76kb
Run npm start to try your app locally.
> Using @sveltejs/adapter-node
TypeError: Cannot read property 'headers' of undefined
at Object.handle (file:///Users/me/sveltekit-demo/.svelte/output/server/app.js:1890:19)
at async ssr (file:///Users/me/sveltekit-demo/.svelte/output/server/app.js:1677:12)
at async visit (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:531:20)
at async prerender (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:682:5)
at async Builder.prerender (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:743:4)
at async adapt (/Users/me/sveltekit-demo/node_modules/@sveltejs/adapter-node/index.js:26:4)
at async adapt (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:765:2)
at async file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/cli.js:598:5
> 500 /about
Error: 500 /about
at error (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:523:11)
at visit (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:574:5)
at async prerender (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:682:5)
at async Builder.prerender (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:743:4)
at async adapt (/Users/me/sveltekit-demo/node_modules/@sveltejs/adapter-node/index.js:26:4)
at async adapt (file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/chunks/index5.js:765:2)
at async file:///Users/me/sveltekit-demo/node_modules/@sveltejs/kit/dist/cli.js:598:5
npm ERR! code 1
npm ERR! path /Users/me/sveltekit-demo
npm ERR! command failed
npm ERR! command sh -c svelte-kit build
about.svelte
is nothing special:
<h1>About this site</h1>
<p>TODO...</p>
svelte.config.cjs
contains adapter as: adapter: node(),
.
Information about your SvelteKit Installation:
System:
OS: macOS 11.2.2
CPU: (8) arm64 Apple M1
Shell: 5.8 - /bin/zsh
npmPackages:
@sveltejs/kit: next => 1.0.0-next.64
svelte: ^3.35.0 => 3.35.0
Severity
Minor
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:20 (8 by maintainers)
Top Results From Across the Web
Order of hooks error when rendering different components
It happens because some custom prop is landing on a native DOM element (like <div setDialogConfiguration={setDialogConfiguration}></div> ) must ...
Read more >Error Handling in React Hooks - Medium
Error Handling in Hooks is quite Simple. In this article, we are going to demonstrate how to handle errors in React Hooks.
Read more >Invalid Hook Call Warning - React
Invalid Hook Call Warning ... You are probably here because you got the following error message: Hooks can only be called inside the...
Read more >Understanding common frustrations with React Hooks
We'll discuss the problem React Hooks intends to solve, what was wrong with the class component, as well as common error messages you...
Read more >Solving React Hooks' invalid hook call warning - Rob Kendal
The warning can be fairly misleading if, like me, you've followed all the Hooks rules and the tool you're building is working in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
config.kit.ssr has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle. how can i resolve this issue
In the process of trying to figure out how we’d tackle this, I ended up writing the code, so I took the liberty of opening a PR: https://github.com/sveltejs/kit/pull/833