Welcome, future TanStack wizard! In this exciting journey, we’re going to unlock the full potential of the TanStack ecosystem, building powerful, performant, and maintainable web applications. But before we can build our masterpiece, we need a solid foundation. Think of this chapter as setting up your ultimate developer workshop โ clean, organized, and ready for action!
This chapter is all about getting our hands dirty with the initial project setup. We’ll choose modern, efficient tools to create a robust development environment tailored for TanStack. By the end of this chapter, you’ll have a fully functional React application, powered by Vite and TypeScript, with the core TanStack libraries installed and ready to go. No prior TanStack knowledge is required, just a basic understanding of React and JavaScript/TypeScript.
๐ Getting Started: Why a Modern Setup Matters
In today’s fast-paced frontend world, choosing the right tools for your development environment can dramatically impact your productivity, application performance, and overall developer experience. We’re aiming for a setup that is:
- Fast: Quick build times and hot module reloading (HMR) for instant feedback.
- Type-Safe: Leverage TypeScript to catch errors early and improve code readability.
- Scalable: A structure that can grow with your application’s complexity.
- Modern: Using tools that align with current best practices and community adoption.
Let’s look at the key players in our setup:
Vite: Your Speedy Development Server
Vite (French for “fast,” pronounced /vit/) is a next-generation frontend tooling that focuses on speed. It provides a lightning-fast development server with instant Hot Module Replacement (HMR) and an optimized build process. Unlike traditional bundlers that bundle your entire application before serving, Vite leverages native ES modules, allowing the browser to handle much of the module resolution. This means incredibly fast startup times, even for large projects!
React: The UI Foundation
React remains a dominant force in UI development, known for its component-based architecture and declarative approach. TanStack libraries are framework-agnostic at their core, but they offer excellent adapters for React, making them a natural fit. We’ll be using React to build our user interfaces throughout this guide.
TypeScript: Adding Type Safety
TypeScript is an absolute game-changer for larger applications and teams. It extends JavaScript by adding static type definitions, which helps prevent common runtime errors, provides excellent autocompletion in your editor, and makes your code more self-documenting. Given the type-safe nature of TanStack libraries, using TypeScript is highly recommended and will be integral to our learning.
Node.js & npm/pnpm/Yarn: The Backbone
You’ll need Node.js installed on your machine, as it provides the JavaScript runtime environment for our development tools and package managers. We’ll use a package manager (like npm, pnpm, or Yarn) to install all our project dependencies. For consistency, we’ll primarily use npm in this guide, but feel free to substitute with your preferred manager.
Mental Model Check: Imagine you’re building a house. Node.js is the construction site’s power grid, npm is your tool rental service, Vite is the super-efficient construction crew, React provides the blueprints for each room, and TypeScript is the quality control inspector ensuring everything fits perfectly.
๐ ๏ธ Step-by-Step Implementation: Building Our Workspace
Let’s get our hands on the keyboard and set up our project!
Step 1: Verify Node.js Installation
First things first, let’s ensure you have Node.js installed. Open your terminal or command prompt and run:
node -v
npm -v
As of January 2026, we recommend using a Node.js LTS (Long Term Support) version, such as v20.x or v22.x. If you don’t have Node.js, please install it from the official Node.js website.
Step 2: Create a New Vite Project
We’ll use Vite to bootstrap our React application with TypeScript. Navigate to your desired development directory in your terminal and run the following command:
npm create vite@latest
This command uses npm create to execute the vite package, specifically the latest version, which is v5.x as of our current date. It will prompt you for some project details:
- Project name: Let’s call it
tanstack-ecosystem-app. - Select a framework: Choose
React. - Select a variant: Choose
TypeScript.
Here’s how the interaction might look in your terminal:
? Project name: โบ tanstack-ecosystem-app
? Select a framework: โบ React
? Select a variant: โบ TypeScript
After you make your selections, Vite will create a new directory named tanstack-ecosystem-app with a basic React + TypeScript project structure.
Step 3: Navigate and Install Dependencies
Now, change into your new project directory and install the initial dependencies:
cd tanstack-ecosystem-app
npm install
The npm install command reads the package.json file generated by Vite and downloads all the necessary packages (like React, ReactDOM, Vite itself, and their TypeScript types) into a node_modules folder.
Step 4: Run Your Application (First Look!)
Let’s see our fresh application in action!
npm run dev
This command starts the Vite development server. You’ll typically see a message like:
VITE v5.x.x ready in X ms
โ Local: http://localhost:5173/
โ Network: use --host to expose
โ press h + enter to show help
Open your web browser and navigate to http://localhost:5173/ (or whatever port Vite indicates). You should see the default Vite + React welcome page. Congratulations, your base application is up and running!
You can stop the development server by pressing Ctrl + C in your terminal.
Step 5: Install Core TanStack Libraries
Now for the main event! We’ll install the foundational TanStack libraries that we’ll explore throughout this course. For this chapter, we’ll focus on TanStack Query, TanStack Router, and TanStack Table as they represent different facets of the ecosystem (data fetching, routing, UI components).
Run the following command in your project root:
npm install @tanstack/react-query@5 @tanstack/react-router@1 @tanstack/react-table@8
Let’s break down this command:
npm install: The command to add new packages.@tanstack/react-query@5: Installs the React adapter for TanStack Query, specifically version 5, which is the latest stable major version. This library is crucial for managing server state.@tanstack/react-router@1: Installs the React adapter for TanStack Router, version 1. This provides type-safe, developer-friendly routing.@tanstack/react-table@8: Installs the React adapter for TanStack Table, version 8. This is a headless UI library for building powerful tables.
After running this, your package.json file will be updated with these new dependencies. You can open package.json to verify:
{
"name": "tanstack-ecosystem-app",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.X.X", // Version will be specific, e.g., ^5.28.1
"@tanstack/react-router": "^1.X.X", // Version will be specific, e.g., ^1.10.0
"@tanstack/react-table": "^8.X.X", // Version will be specific, e.g., ^8.11.3
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
}
(Note: The exact minor/patch versions for TanStack libraries will vary, but the major versions 5, 1, and 8 are correct as of Jan 2026.)
๐จ Mini-Challenge: Add a Placeholder Component
Let’s make a tiny change to confirm our environment is ready for TanStack.
Challenge:
- Open
src/App.tsx. - Import
QueryClientandQueryClientProviderfrom@tanstack/react-query. - Wrap your existing
Appcomponent’s JSX withQueryClientProviderand create aqueryClientinstance. This won’t do anything yet, but it’s a critical setup step for TanStack Query.
Hint:
Remember to instantiate QueryClient outside your component function to avoid re-creating it on every render.
What to Observe/Learn:
You should see no visual change in your browser, but the application should still compile and run without errors. This confirms that @tanstack/react-query is correctly installed and its components are available for use.
Solution (Don’t peek until you’ve tried!):
Your src/App.tsx should look something like this:
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
import {
QueryClient,
QueryClientProvider,
} from '@tanstack/react-query' // Import these
// Create a client
const queryClient = new QueryClient() // Instantiate QueryClient outside the component
function App() {
const [count, setCount] = useState(0)
return (
// Wrap your content with QueryClientProvider
<QueryClientProvider client={queryClient}>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit `src/App.tsx` and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</QueryClientProvider> // Close the provider
)
}
export default App
๐จ Common Pitfalls & Troubleshooting
Even with a straightforward setup, you might encounter a few bumps. Here are some common issues and how to tackle them:
- “command not found: npm” or “node”: This means Node.js isn’t installed or isn’t in your system’s PATH. Revisit Step 1 and ensure Node.js is correctly installed. Restarting your terminal can sometimes help.
- Dependency Installation Errors: If
npm installfails, check your internet connection. Also, older versions of Node.js or npm can sometimes cause issues. Try updating npm:npm install -g npm@latest. - Vite Server Not Starting: If
npm run devdoesn’t work, check your terminal for error messages. Common culprits are port conflicts (another application is using port 5173). Vite usually suggests an alternative port. Ensure you are in the correct project directory (tanstack-ecosystem-app). - TypeScript Errors (after adding TanStack Query): If you see red squiggly lines in your editor or build errors related to types, ensure your
tsconfig.jsonis correctly configured (Vite usually handles this well). Sometimes an IDE restart helps. Also, ensure you’re using the correct major versions for@tanstack/react-queryand yourreactversion.
๐ Summary
Phew! You’ve successfully laid the groundwork for our TanStack learning adventure. Here’s a quick recap of what we accomplished:
- Initialized a new project: Used
npm create vite@latestto set up a React and TypeScript project. - Understood key tools: Explored why Vite, React, and TypeScript are excellent choices for modern web development.
- Installed core TanStack libraries: Added
@tanstack/react-query@5,@tanstack/react-router@1, and@tanstack/react-table@8to our project. - Verified our setup: Ran the development server and made a small code change to confirm everything is working.
You now have a clean, fast, and type-safe development environment ready to dive deep into the TanStack ecosystem. In the next chapter, we’ll begin our exploration with TanStack Query, understanding how it revolutionizes data fetching and state management in your applications!
References
- Vite Official Documentation
- React Official Documentation
- TypeScript Official Documentation
- Node.js Official Website
- TanStack Query v5 Documentation
- TanStack Router v1 Documentation
- TanStack Table v8 Documentation
This page is AI-assisted and reviewed. It references official documentation and recognized resources where relevant.