Manage dependencies in a large Replit project using three layers: language-level package managers (npm for Node.js, pip for Python), system-level Nix packages for native binaries, and the GUI package manager in the Tools dock. Use replit.nix for system dependencies like image libraries or database clients, package.json or requirements.txt for application dependencies, and the onBoot command to ensure everything installs automatically on startup.
Manage Dependencies in Large Replit Projects with npm, pip, and Nix
Large projects often need more than just npm packages — they need system-level libraries, database clients, image processors, or other native binaries that package managers alone cannot provide. Replit uses a layered dependency system: language package managers (npm, pip, poetry) for application code, Nix for system-level packages, and a GUI tool for quick installs. This tutorial explains how all three layers work together and how to configure them for a large, stable project.
Prerequisites
- A Replit account on any plan (Core or Pro recommended for large projects)
- A Replit App with existing code
- Basic familiarity with the Shell tab and package managers
- No prior experience with Nix required
Step-by-step guide
Install application dependencies with npm or pip
Install application dependencies with npm or pip
Open the Shell tab and use your language's package manager to install dependencies. For Node.js projects, use npm install. For Python, use pip install. These install packages into your project directory (node_modules for npm, a virtual environment for pip). Always use --save or --save-dev flags with npm so dependencies are recorded in package.json. For pip, generate a requirements.txt file after installing packages so the list is reproducible.
1# Node.js — install and save to package.json2npm install express cors dotenv3npm install --save-dev jest typescript45# Python — install and freeze to requirements.txt6pip install flask requests sqlalchemy7pip freeze > requirements.txtExpected result: Packages are installed and recorded in package.json or requirements.txt. Running 'npm ls' or 'pip list' in Shell shows the installed packages.
Use the GUI package manager for quick installs
Use the GUI package manager for quick installs
Replit provides a graphical package manager accessible from the Tools dock. Click the Dependencies tool (or search for 'Packages' in the search bar) to open it. Type a package name to search, then click the install button. The GUI handles the installation command for you and adds the package to your dependency file automatically. This is useful for beginners or when you want to browse available packages without memorizing exact names.
Expected result: Packages install through the GUI and appear in your package.json or requirements.txt the same way as Shell-installed packages.
Configure replit.nix for system-level dependencies
Configure replit.nix for system-level dependencies
Some packages need system libraries that npm or pip cannot provide — for example, image processing libraries need libvips, database clients need PostgreSQL headers, and PDF generation needs poppler. Replit uses Nix to manage these system-level dependencies. Open .replit (enable 'Show hidden files'), then open replit.nix. Add the required system packages to the deps array. Search for available packages at search.nixos.org/packages. After editing replit.nix, type 'exit' in Shell to restart the environment and load the new packages.
1# replit.nix — system-level dependencies2{ pkgs }: {3 deps = [4 pkgs.nodejs-20_x5 pkgs.nodePackages.typescript-language-server6 pkgs.python3117 pkgs.postgresql8 pkgs.libvips9 pkgs.ffmpeg10 pkgs.imagemagick11 ];12}Expected result: After running 'exit' in Shell, the system packages are available. You can verify by running the package command (e.g., 'ffmpeg --version' or 'psql --version') in Shell.
Add quick Nix packages via the .replit file
Add quick Nix packages via the .replit file
For simpler system dependencies, you can skip editing replit.nix and add packages directly in the .replit file under the [nix] section. This is a quicker method for small additions. The packages listed here are installed alongside those in replit.nix. Make sure the Nix channel is set to a recent stable version to ensure package compatibility.
1# .replit file — quick Nix packages2[nix]3channel = "stable-24_05"4packages = ["cowsay", "htop", "curl", "jq"]Expected result: The listed packages are available in Shell after the environment restarts. Running 'htop' or 'jq --version' confirms availability.
Set up onBoot for automatic dependency installation
Set up onBoot for automatic dependency installation
To ensure dependencies install automatically whenever the Repl starts (especially after a restart or when a collaborator opens the project), add an onBoot command to your .replit file. This runs once at startup and handles the initial setup. For projects that use both npm and pip, chain the commands with &&.
1# .replit file2onBoot = "npm install && pip install -r requirements.txt"Expected result: Opening the Repl automatically installs all application dependencies. Collaborators do not need to manually run npm install or pip install.
Monitor storage usage and manage dependency sizes
Monitor storage usage and manage dependency sizes
Large projects with many dependencies can hit storage limits, especially on the Starter plan (approximately 2 GiB). Check your current storage usage by clicking the Resources panel (stacked computers icon in the left sidebar). It shows RAM, CPU, and storage breakdown. To reduce dependency size, remove unused packages with npm prune or pip uninstall, avoid installing heavy packages globally, and use .replit hidden to hide large directories like node_modules from the file tree without deleting them.
1# Check disk usage from Shell2du -sh node_modules/3du -sh .local/45# Remove unused npm packages6npm prune78# Remove a specific unused package9npm uninstall unused-package-nameExpected result: You can see your current storage usage in the Resources panel and identify which directories consume the most space.
Complete working example
1# .replit — dependency management for a large project23entrypoint = "src/index.js"4modules = ["nodejs-20:v8-20230920-bd784b9"]56# Install dependencies automatically on startup7onBoot = "npm install"89# Run the application10run = "node src/index.js"1112# Quick system packages13[nix]14channel = "stable-24_05"15packages = ["curl", "jq"]1617# Environment variables for development18[run.env]19NODE_ENV = "development"2021# Deployment configuration22[deployment]23build = ["sh", "-c", "npm ci && npm run build"]24run = ["sh", "-c", "NODE_ENV=production node dist/index.js"]25deploymentTarget = "cloudrun"2627# Port configuration28[[ports]]29localPort = 300030externalPort = 803132# Hide large/generated directories from file tree33hidden = [34 ".config",35 "package-lock.json",36 "node_modules",37 ".local",38 "dist",39 ".cache"40]Common mistakes when managing dependencies in Replit
Why it's a problem: Not running 'exit' in Shell after editing replit.nix, so new system packages are not loaded
How to avoid: After any change to replit.nix, type 'exit' in Shell. This restarts the Nix environment and loads the new packages.
Why it's a problem: Using the wrong package name format in replit.nix (e.g., 'nodejs' instead of 'pkgs.nodejs-20_x')
How to avoid: Search for the exact package name at search.nixos.org/packages. Always use the pkgs. prefix in replit.nix.
Why it's a problem: Running out of storage on the Starter plan due to large node_modules
How to avoid: Run 'npm prune' to remove unused packages. Check 'du -sh node_modules/' to see the size. Consider upgrading to Core (50 GiB) for large projects.
Why it's a problem: Installing packages globally instead of as project dependencies
How to avoid: Use 'npm install package-name' (not npm install -g) so packages are project-scoped and available to all collaborators and deployments.
Best practices
- Always record dependencies in package.json (npm) or requirements.txt (pip) so the project is reproducible
- Use replit.nix for system-level libraries and npm/pip for application-level packages — do not mix their responsibilities
- Set onBoot in .replit to automatically install dependencies when the Repl starts
- Run 'exit' in Shell after editing replit.nix to reload the Nix environment
- Use the Resources panel to monitor storage and identify oversized dependency directories
- Hide node_modules, .local, and .cache in the .replit hidden array to keep the file tree navigable
- Use npm ci instead of npm install in deployment builds for deterministic, faster installations
- Search for Nix packages at search.nixos.org/packages to find exact package names before adding them to replit.nix
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I have a large Node.js project in Replit that needs system-level dependencies like PostgreSQL and image processing. How do I configure replit.nix and package.json to manage both system and application dependencies?
Configure dependency management for this project. Add PostgreSQL, libvips, and ffmpeg to replit.nix. Set up onBoot in .replit to run npm install automatically. Add node_modules and .cache to the hidden array. Show me how to check storage usage.
Frequently asked questions
npm packages are JavaScript/Node.js libraries for your application code (Express, React, etc.). Nix packages are system-level binaries and libraries (PostgreSQL, FFmpeg, ImageMagick) that run on the operating system. You need both for projects that depend on native system tools.
Starter plan provides approximately 2 GiB. Core plan provides 50 GiB. Pro plan provides 50+ GiB. Nix packages from Replit's prebuilt cache do not count against your quota.
npm packages in node_modules persist across restarts. However, setting onBoot = "npm install" in .replit ensures any missing packages are restored automatically. Nix packages are always available after replit.nix is configured.
Yes. Agent v4 automatically installs dependencies when building applications. It configures package.json, replit.nix, and installs packages as needed. You can also prompt Agent directly: 'Install PostgreSQL client and image processing libraries for this project.'
The deployment build step runs in a clean environment. Include npm ci or npm install in the [deployment] build command. Nix packages from replit.nix are available in deployments automatically.
Replit supports polyglot projects. Add both Node.js and Python modules to your .replit file. Use npm install for JavaScript packages and pip install for Python packages. Set onBoot to install both: 'npm install && pip install -r requirements.txt'.
Common causes: wrong package name (check search.nixos.org), outdated Nix channel (update to stable-24_05 or later), or unfree packages not enabled. Check the exact error by running 'cat /run/replit/env/error' in Shell.
For projects with complex dependency trees, native module conflicts, or multi-language requirements, the RapidDev team can help set up a clean, scalable dependency management strategy that prevents version conflicts and keeps builds fast.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation