0
0
SvelteHow-ToBeginner · 3 min read

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

To create a Svelte project, run npm create svelte@latest my-app in your terminal, then follow the prompts to select options. After that, navigate into your 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 Svelte project is npm create svelte@latest <project-name>. Here:

  • npm create runs a package initializer.
  • svelte@latest specifies the official Svelte template at the latest version.
  • <project-name> is the folder name for your new project.

After creation, use npm install to add dependencies and npm run dev to start the local server.

bash
npm create svelte@latest my-app
cd my-app
npm install
npm run dev
💻

Example

This example shows creating a Svelte project named my-app, installing dependencies, and running the development server. The server will be available at http://localhost:5173 by default.

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 Svelte project include:

  • Not having Node.js installed or using an outdated version (use Node 16 or newer).
  • Skipping npm install after creating the project, which causes missing dependencies.
  • Running npm run dev outside the project folder.
  • Ignoring prompts during project creation and choosing incompatible options.

Always check your terminal for errors and ensure you are in the correct directory.

bash
# Wrong: running dev outside project folder
npm run dev

# Right:
cd my-app
npm run dev
📊

Quick Reference

CommandPurpose
npm create svelte@latest my-appCreate new Svelte project named my-app
cd my-appChange directory to project folder
npm installInstall project dependencies
npm run devStart development server

Key Takeaways

Use the command 'npm create svelte@latest ' to start a new Svelte project.
Always run 'npm install' inside your project folder before starting the server.
Run 'npm run dev' inside the project folder to launch the development server.
Ensure Node.js version 16 or higher is installed before creating the project.
Follow the prompts carefully during project creation to select suitable options.