Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SvelteKit: "Error: request.query has been replaced by request.url.searchParams"

I wanted to try out SvelteKit on MacOs 11.5.2. Using node v16.13.1, npm 8.1.2.

I have installed the SvelteKit as per original guidance:

npm init svelte@next my-app
cd my-app
npm install
npm run dev -- --open

Then, when localhost:3000 opens, I get this error:

**Error: request.query has been replaced by request.url.searchParams**
    at Object.get (file:///Web/Svelte_30-12-21/my-app/node_modules/@sveltejs/kit/dist/ssr.js:1753:12)
    at Object.handle (/Web/Svelte_30-12-21/my-app/src/hooks.ts:10:30)
    at respond (file:///Web/Svelte_30-12-21/my-app/node_modules/@sveltejs/kit/dist/ssr.js:1764:30)
    at svelteKitMiddleware (file:///Web/Svelte_30-12-21/my-app/node_modules/@sveltejs/kit/dist/chunks/index.js:4577:28)

What could be the problem?

like image 517
Cluendo Avatar asked Dec 22 '22 14:12

Cluendo


2 Answers

I ran into the same problem. In src/hooks.js replace

const method = request.query.get('_method');

with

const method = request.method;

If you are using npm init svelte@next my-app and using the demo app, you are also going to run into a problem in Header.svelte.

replace

<li class:active={$page.path === '/'}><a sveltekit:prefetch href="/">Home</a></li>
<li class:active={$page.path === '/about'}><a sveltekit:prefetch href="/about">About</a></li>
<li class:active={$page.path === '/todos'}><a sveltekit:prefetch href="/todos">Todos</a></li>

with

<ul>
  <li class:active={$page.url.pathname === '/'}><a sveltekit:prefetch href="/">Home</a></li>
  <li class:active={$page.url.pathname === '/about'}>
   <a sveltekit:prefetch href="/about">About</a>
  </li>
  <li class:active={$page.url.pathname === '/todos'}>
    <a sveltekit:prefetch href="/todos">Todos</a>
  </li>
</ul>
like image 71
klequis Avatar answered Feb 06 '23 22:02

klequis


The issue has been introduced in a commit made earlier today and reported. It has been fixed already, run npm update or delete your node_modules directory and reinstall.

like image 25
Thomas Hennes Avatar answered Feb 06 '23 23:02

Thomas Hennes