Skip to main content
RapidDev - Software Development Agency
replit-tutorial

Why Replit builds are slow

Slow Replit builds are usually caused by bloated node_modules, missing caches, and unoptimized .replit configuration. Speed up builds by trimming unused dependencies, configuring the onBoot command for pre-caching, leveraging Nix package caching, and using the correct Nix channel. These changes can cut build times by half or more on both free and paid plans.

What you'll learn

  • Identify why Replit builds are slow in your project
  • Configure onBoot in .replit to cache dependencies across restarts
  • Optimize your Nix environment to avoid redundant package downloads
  • Trim node_modules and reduce overall project storage usage
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner7 min read15 minutesAll Replit plans (Starter, Core, Pro, Enterprise)March 2026RapidDev Engineering Team
TL;DR

Slow Replit builds are usually caused by bloated node_modules, missing caches, and unoptimized .replit configuration. Speed up builds by trimming unused dependencies, configuring the onBoot command for pre-caching, leveraging Nix package caching, and using the correct Nix channel. These changes can cut build times by half or more on both free and paid plans.

Why Replit Builds Are Slow and How to Fix Them

If your Replit project takes minutes to install dependencies or start up, you are not alone. Multi-module codebases with large dependency trees are especially prone to slow builds on Replit because every restart may re-download packages, and misconfigured Nix environments add overhead. This tutorial explains the most common causes of slow builds and walks you through concrete optimizations in your .replit and replit.nix files.

Prerequisites

  • A Replit account with an existing project (any plan)
  • A project with npm, pip, or another package manager configured
  • Basic understanding of what .replit and replit.nix files do
  • Access to the Shell tab in Replit

Step-by-step guide

1

Identify what is slowing your build

Open the Shell from the Tools dock and run your install command manually (e.g., npm install or pip install -r requirements.txt) to see how long it takes. Then check your storage usage by clicking the Resources panel icon (stacked computers). Large node_modules folders, duplicate dependencies, and oversized Nix environments are the three most common culprits. Run du -sh node_modules to see the exact size. Anything over 500 MB is a warning sign.

typescript
1# Check node_modules size
2du -sh node_modules
3
4# Check total project size
5du -sh .
6
7# List largest directories
8du -h --max-depth=1 | sort -rh | head -10

Expected result: You see the exact size of your dependency folder and can identify which directories consume the most space.

2

Remove unused dependencies

Audit your package.json for dependencies you no longer use. Every unnecessary package adds to install time and storage. Run npx depcheck to find unused packages in Node.js projects. For Python, check your imports against requirements.txt manually. Remove anything that is not actively imported in your source code. This single step can dramatically reduce install times.

typescript
1# Find unused Node.js dependencies
2npx depcheck
3
4# Remove an unused package
5npm uninstall unused-package-name
6
7# Clean npm cache to free storage
8npm cache clean --force

Expected result: Your package.json contains only the dependencies your project actually needs, and node_modules is smaller.

3

Configure onBoot in .replit for dependency caching

The onBoot command in your .replit file runs every time the Repl wakes up. By placing your install command here, Replit caches installed packages across restarts instead of re-downloading them each time you click Run. Open the .replit file (enable Show hidden files in the file tree menu if you do not see it) and add an onBoot line. This is especially important for Autoscale deployments where cold starts re-initialize the environment.

typescript
1# Add this to your .replit file
2onBoot = "npm install --prefer-offline"

Expected result: After restarting your Repl, dependencies install faster because npm uses its local cache instead of downloading everything from the registry.

4

Optimize your Nix channel and packages

Replit uses Nix for system-level packages. An outdated Nix channel forces unnecessary recompilation. Open your .replit file and check the [nix] channel value. Update it to a recent stable channel like stable-24_05. Also ensure your replit.nix file only includes packages you actually need. Replit maintains a large prebuilt cache for common packages, so using standard package names avoids compilation from source. After changes, run exit in Shell to reload the Nix environment.

typescript
1# In .replit, update the Nix channel
2[nix]
3channel = "stable-24_05"
4packages = ["nodejs-20_x"]

Expected result: Your Nix environment loads faster because it uses prebuilt cached packages from a current stable channel.

5

Split build and run commands

If your Run command includes both a build step and a start step, the build runs every time you click Run. Separate these by putting the build step in onBoot or a dedicated build script and keeping only the start command in run. For deployments, use the [deployment] section to define separate build and run commands. This prevents redundant compilation during development.

typescript
1# .replit configuration
2onBoot = "npm install --prefer-offline && npm run build"
3run = "node dist/index.js"
4
5[deployment]
6build = ["npm", "run", "build"]
7run = ["node", "dist/index.js"]

Expected result: Clicking Run starts your app immediately without rebuilding, since the build output already exists from onBoot.

6

Monitor resource usage during builds

Click the Resources panel icon (stacked computers) in the left sidebar while your build runs. Watch RAM and CPU usage in real time. If RAM usage spikes near the limit (2 GiB on Starter, 8 GiB on Core), your build may crash with an out-of-memory error. For Node.js projects, you can limit memory usage with the --max-old-space-size flag. If builds consistently max out resources, consider upgrading your plan or reducing the scope of each build.

typescript
1# Set Node.js memory limit for builds
2NODE_OPTIONS="--max-old-space-size=4096" npm run build

Expected result: You can see real-time CPU and RAM consumption during builds and identify whether resource limits are causing build failures.

Complete working example

.replit
1# Optimized .replit configuration for fast builds
2
3entrypoint = "src/index.js"
4
5# Cache dependencies on boot instead of every Run
6onBoot = "npm install --prefer-offline"
7
8# Only start the app on Run (no rebuild)
9run = ["node", "src/index.js"]
10
11# Hide noise from file tree
12hidden = [".config", "node_modules", "package-lock.json"]
13
14[nix]
15# Use a recent stable channel for prebuilt cache hits
16channel = "stable-24_05"
17# Only include system packages you actually need
18packages = ["nodejs-20_x"]
19
20[[ports]]
21localPort = 3000
22externalPort = 80
23
24[deployment]
25# Separate build and run for deployments
26build = ["npm", "run", "build"]
27run = ["node", "dist/index.js"]
28deploymentTarget = "cloudrun"
29
30[run.env]
31NODE_ENV = "development"

Common mistakes

Why it's a problem: Putting npm install inside the run command so it runs every time you click Run

How to avoid: Move npm install to the onBoot field in .replit so it only runs when the Repl starts up

Why it's a problem: Using an outdated Nix channel that forces packages to compile from source

How to avoid: Update the [nix] channel in .replit to stable-24_05 or newer, then run exit in Shell

Why it's a problem: Ignoring storage usage until the Repl runs out of space and builds fail silently

How to avoid: Check the Resources panel regularly and run du -sh node_modules to track dependency size

Why it's a problem: Installing global npm packages that disappear on every restart

How to avoid: Use local project dependencies in package.json or add the tool to replit.nix instead

Best practices

  • Always use onBoot for dependency installation so packages persist across Repl restarts
  • Use the --prefer-offline flag with npm install to skip network requests for cached packages
  • Keep your Nix channel updated to a recent stable version for maximum prebuilt cache coverage
  • Remove unused dependencies regularly with npx depcheck to reduce install time and storage
  • Separate build and run commands so clicking Run does not trigger a full rebuild every time
  • Monitor the Resources panel during builds to catch out-of-memory issues before they crash your Repl
  • Use hidden files configuration in .replit to keep the file tree clean without deleting needed files
  • Set NODE_OPTIONS with --max-old-space-size when builds fail due to memory limits

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

My Replit project takes over 3 minutes to install dependencies every time I restart. My .replit file uses run = 'npm install && node index.js'. How can I restructure my configuration to cache dependencies and speed up builds?

Replit Prompt

My app is slow to start. Optimize the .replit and replit.nix configuration to cache npm dependencies across restarts and reduce build times. Move the install step to onBoot and update the Nix channel to stable-24_05.

Frequently asked questions

If your run command includes npm install, it executes on every Run click. Move the install step to the onBoot field in your .replit file so it only runs when the Repl first wakes up, and cached packages persist across restarts.

Yes. Replit maintains a large prebuilt cache for common Nix packages. Using standard package names from a current stable channel ensures cache hits. Custom or uncommon packages may compile from source, which is slower.

The free Starter plan provides approximately 2 GiB of storage. Large node_modules folders can consume most of this. Core provides 50 GiB and Pro provides 50 GiB or more.

No. The flag tells npm to prefer cached versions but still downloads from the registry if a required version is not cached locally. It speeds up installs when your lock file has not changed.

Yes. Replit supports pnpm and it is available in the Shell by default. pnpm uses a content-addressable store that can significantly reduce install times and storage usage compared to npm.

The Starter plan has 2 GiB RAM and Core has 8 GiB. Large builds can exceed these limits. Set NODE_OPTIONS with --max-old-space-size to cap memory usage, and run kill 1 to free memory from stuck processes before retrying.

The onBoot command runs once when the Repl environment initializes. The run command executes every time you click the Run button. Use onBoot for setup tasks like installing dependencies and run for starting your application.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.