Skip to main content
Get started with Svelte Query by installing the package and setting up your application.

Requirements

Svelte Query requires:
  • Svelte 5.25.0 or higher - Uses modern Svelte 5 runes ($state, $derived, $effect)
  • TypeScript 4.7+ (recommended) - For full type safety
  • Node.js 18+ - For development
Svelte Query is built specifically for Svelte 5 and uses runes. It will not work with Svelte 3 or 4. For older versions of Svelte, use a different data fetching solution.

Installation

1

Install the package

Install @tanstack/svelte-query using your preferred package manager:
This will install @tanstack/svelte-query version 6.0.18 or higher, which includes:
  • Core query functionality
  • TypeScript type definitions
  • Svelte 5 rune-based reactivity
2

Set up the QueryClientProvider

Create a QueryClient and wrap your application with QueryClientProvider in your root layout:
+layout.svelte
In SvelteKit applications, place this in your root +layout.svelte file to make the QueryClient available throughout your app.
3

Start using queries

You can now use Svelte Query hooks in any component:
+page.svelte

Configuration Options

The QueryClient accepts various configuration options to customize its behavior:

Common Configuration Patterns

SvelteKit Integration

For SvelteKit applications, you may want to handle browser-specific features:
+layout.svelte
Setting enabled: browser prevents queries from running during server-side rendering, which is useful for client-only data fetching.

Optional: Install DevTools

For development, install the Svelte Query DevTools to visualize and debug your queries:
Then add it to your layout:
+layout.svelte
The DevTools only render in development mode and are automatically tree-shaken from production builds.

Package Dependencies

Svelte Query has a minimal dependency footprint:
package.json
  • @tanstack/query-core - Framework-agnostic core query logic
  • svelte - Required peer dependency (version 5.25.0+)

Troubleshooting

Error: “Svelte version 5.25.0 or higher is required”

Ensure you have Svelte 5.25.0+ installed:

Error: “Cannot find QueryClient in context”

Make sure you’ve wrapped your app with QueryClientProvider:

TypeScript errors with runes

Ensure your tsconfig.json is configured for Svelte 5:
tsconfig.json

Next Steps

1

Quick Start Guide

Learn the basics with a step-by-step tutorial.Quick Start →
2

TypeScript Configuration

Set up TypeScript for maximum type safety.TypeScript Guide →
3

Configure DevTools

Learn how to use the Svelte Query DevTools.DevTools Setup →