0
0
SvelteHow-ToBeginner · 3 min read

How to Create a SvelteKit Project: Step-by-Step Guide

To create a SvelteKit project, run npm create svelte@latest my-app in your terminal, then follow the prompts to select options. After that, navigate into the project folder and run npm install to install dependencies, and npm run dev to start the development server.
📐

Syntax

The basic command to create a new SvelteKit project is:

  • npm create svelte@latest <project-name>: This runs the official SvelteKit project initializer.
  • cd <project-name>: Change directory into your new project folder.
  • npm install: Installs all required packages for your project.
  • npm run dev: Starts the local development server to preview your app.
bash
npm create svelte@latest my-app
cd my-app
npm install
npm run dev
💻

Example

This example shows how to create a new SvelteKit project named my-app, install dependencies, and start the development server. You will see a local URL where your app runs.

bash
npm create svelte@latest my-app
cd my-app
npm install
npm run dev
Output
VITE v4.3.9 ready in 300 ms ➜ Local: http://localhost:5173/ ➜ Network: use --host to expose
⚠️

Common Pitfalls

Some common mistakes when creating a SvelteKit project include:

  • Not having Node.js installed or using an outdated version (SvelteKit requires Node.js 16 or newer).
  • Running npm install before creating the project folder.
  • Not navigating into the project folder before running commands.
  • Ignoring prompts during project setup which select important options like TypeScript or ESLint.

Always follow the prompts carefully and ensure your environment meets requirements.

bash
Wrong:
npm install
npm create svelte@latest my-app

Right:
npm create svelte@latest my-app
cd my-app
npm install
📊

Quick Reference

Summary tips for creating a SvelteKit project:

  • Use npm create svelte@latest <project-name> to start.
  • Follow prompts to choose features like TypeScript or testing.
  • Run npm install inside the project folder.
  • Start development with npm run dev.
  • Open http://localhost:5173/ in your browser to see your app.

Key Takeaways

Use the command npm create svelte@latest <project-name> to create a new SvelteKit project.
Always navigate into your project folder before installing dependencies with npm install.
Run npm run dev to start the development server and preview your app locally.
Make sure your Node.js version is 16 or higher to avoid compatibility issues.
Follow the setup prompts carefully to select the right options for your project.