0
0
SvelteHow-ToBeginner · 3 min read

How to Run a Svelte Project: Simple Steps to Start

To run a Svelte project, first install dependencies with npm install, then start the development server using npm run dev. Open http://localhost:5173 in your browser to see your app running.
📐

Syntax

Running a Svelte project involves two main commands:

  • npm install: Installs all required packages listed in package.json.
  • npm run dev: Starts the development server that watches your files and reloads the app automatically.

After running npm run dev, open http://localhost:5173 in your browser to view the app.

bash
npm install
npm run dev
Output
> svelte-project@1.0.0 dev > vite vite v4.x.x dev server running at: > Local: http://localhost:5173/ > Network: use --host to expose ready in 300ms.
💻

Example

This example shows how to run a fresh Svelte project created with npm create vite@latest my-svelte-app -- --template svelte. After navigating into the project folder, run the commands to start the app.

bash
cd my-svelte-app
npm install
npm run dev
Output
> my-svelte-app@1.0.0 dev > vite vite v4.x.x dev server running at: > Local: http://localhost:5173/ Open http://localhost:5173 in your browser to see your Svelte app.
⚠️

Common Pitfalls

1. Forgetting to install dependencies: Running npm run dev before npm install causes errors because packages are missing.

2. Using wrong port: The default port is 5173, not 3000. Make sure to open http://localhost:5173.

3. Not in project folder: Run commands inside your Svelte project directory where package.json is located.

bash
Wrong way:
npm run dev

Right way:
npm install
npm run dev
📊

Quick Reference

CommandPurpose
npm installInstall project dependencies
npm run devStart development server
http://localhost:5173URL to view running app

Key Takeaways

Always run npm install before npm run dev to install dependencies.
Use npm run dev to start the Svelte development server.
Open http://localhost:5173 in your browser to see your app.
Run commands inside your Svelte project folder.
Check the terminal output for the correct local URL and port.