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
Identify what is slowing your build
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.
1# Check node_modules size2du -sh node_modules34# Check total project size5du -sh .67# List largest directories8du -h --max-depth=1 | sort -rh | head -10Expected result: You see the exact size of your dependency folder and can identify which directories consume the most space.
Remove unused dependencies
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.
1# Find unused Node.js dependencies2npx depcheck34# Remove an unused package5npm uninstall unused-package-name67# Clean npm cache to free storage8npm cache clean --forceExpected result: Your package.json contains only the dependencies your project actually needs, and node_modules is smaller.
Configure onBoot in .replit for dependency caching
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.
1# Add this to your .replit file2onBoot = "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.
Optimize your Nix channel and packages
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.
1# In .replit, update the Nix channel2[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.
Split build and run commands
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.
1# .replit configuration2onBoot = "npm install --prefer-offline && npm run build"3run = "node dist/index.js"45[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.
Monitor resource usage during builds
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.
1# Set Node.js memory limit for builds2NODE_OPTIONS="--max-old-space-size=4096" npm run buildExpected result: You can see real-time CPU and RAM consumption during builds and identify whether resource limits are causing build failures.
Complete working example
1# Optimized .replit configuration for fast builds23entrypoint = "src/index.js"45# Cache dependencies on boot instead of every Run6onBoot = "npm install --prefer-offline"78# Only start the app on Run (no rebuild)9run = ["node", "src/index.js"]1011# Hide noise from file tree12hidden = [".config", "node_modules", "package-lock.json"]1314[nix]15# Use a recent stable channel for prebuilt cache hits16channel = "stable-24_05"17# Only include system packages you actually need18packages = ["nodejs-20_x"]1920[[ports]]21localPort = 300022externalPort = 802324[deployment]25# Separate build and run for deployments26build = ["npm", "run", "build"]27run = ["node", "dist/index.js"]28deploymentTarget = "cloudrun"2930[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.
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?
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.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation