How to Install Dev Dependencies in npm? A Complete Guide to Dependencies & Scripts
Updated on Mar 26, 2025 | 16 min read | 108.9k views
Share:
For working professionals
For fresh graduates
More
Updated on Mar 26, 2025 | 16 min read | 108.9k views
Share:
Table of Contents
Did you know that 22 million new project management jobs are expected to be created by 2027? In this high-potential field that demands efficiency and reliability, understanding and properly installing devDependencies in npm have become a must.
Software development involves countless libraries and frameworks for testing, bundling, and code quality checks. DevDependencies are the add-ons you only need while building or refining an application. Keeping them separate from standard dependencies helps your production environment stay slim and stable.
In this blog, you’ll learn how to install dev dependencies in npm and how they compare with other dependencies. You’ll also discover alternative methods and tips for managing them effectively. Dive in!
Development dependencies (known as devDependencies) are tools and libraries needed during the development phase of a project but not necessary in the final production build. These include testing frameworks, transpilers, linters, and bundlers.
devDependencies are listed in the package.json file under the "devDependencies" section. They can be installed using package managers like npm or Yarn to streamline tasks like code testing and compiling.
You can add devDependencies using the following npm commands.
npm install eslint --save-dev
This command will add eslint as a devDependency and update your package.json file.
"devDependencies": {
"eslint": "^8.0.0"
}
Now that you're familiar with development dependencies, let's explore how to install dev dependencies in npm.
You can install devDependencies with npm using two methods:
Here’s the breakdown of both these methods for installing devDependencies.
You can use terminal commands to install a module as a development dependency.
Here’s how to install it on various operating systems.
Open Command Prompt or PowerShell and run the following command:
npm install mocha --save-dev
Open the terminal and run the same command as above:
npm install gulp --save-dev
This command will add a specified module under the devDependencies section in package.json. Here’s what it will look like:
"devDependencies": {
"mocha": "^10.0.0",
"gulp": "^4.0.0"
}
Also Read: How to Install Node.js and npm on Windows? [Step-by-Step]
Perform the following steps to install dependencies manually:
"devDependencies": {
"mocha": "^10.0.0",
"gulp": "^4.0.0"
}
npm install
A situation might arise where you need to pin down a precise version of a devDependency rather than always using the latest release. This ensures consistent builds across different environments, helps prevent unexpected breaking changes, and makes debugging easier by locking in predictable behavior.
Let’s understand the implementation through an example.
Example: Installing a Specific Version of ESLint
Below is a step-by-step walkthrough for installing ESLint at version 7.7.0 as a devDependency.
Step 1: Open Your Project Directory
Navigate to your Node.js project folder in the terminal using this command:
cd /path/to/your-project
Step 2: Install a Specific Package Version
Use the @version notation to specify which version you need:
npm install eslint@7.7.0 --save-dev
Step 3: Verify the Installation
npm list --dev
Step 4: Test Your Setup
Run your ESLint command or script to ensure everything functions properly:
npx eslint --version
Specifying the version during installation allows you to maintain a controlled and stable development environment that reduces compatibility surprises.
Also Read: How to Install a Specific Version of an npm Package?
Observing and confirming the devDependencies present in your Node.js project is essential for maintaining a stable and predictable development environment. npm offers built-in commands and straightforward methods to help you inspect which devDependencies are installed, along with their specific versions.
Below are five key ways to check and confirm your devDependencies:
The quickest way to see all devDependencies installed in your project is by running this command:
npm list --dev
Output
This displays each development dependency nested beneath your project’s name. If you need a simpler, top-level view without nested sub-dependencies, add --depth=0:
npm list --dev --depth=0
Why Does It Help?
It quickly confirms that the devDependencies you expect (like eslint and jest) are currently installed, and shows their installed versions.
Your package.json file explicitly lists all dependencies for your project.
{
"devDependencies": {
"eslint": "^7.7.0",
"jest": "^29.4.2"
}
}
Why Does It Help?
This is your project’s “source of truth”. Even if someone else added or removed a devDependency, this file reflects the intended devDependencies.
Sometimes, devDependencies installed locally may differ in version from what’s declared in package.json. You can quickly verify if your installed packages match what’s declared, or if newer versions are available using this command:
npm outdated --dev
Output
It lists each devDependency, the current installed version, and the wanted (or latest) versions.
Why Does It Help?
It ensures you’re aware of any mismatches or pending updates, especially when working with a team.
If you suspect some devDependencies aren’t installed, the following environment-related npm flags might be the reason:
Flag 1
NODE_ENV: If set to production, npm will skip devDependencies by default.
Flag 2
--production: Running npm install --production omits devDependencies.
By verifying these flags, you can confirm whether you’re in a state that includes all development tools.
Finally, you can manually inspect your node_modules folder or run this command:
npm list <package-name>
Why Does it Help?
It confirms that a specific dependency is physically present in your project. If it's missing, you might need to reinstall it or adjust environment flags.
By following these steps, you'll have a solid grasp of which development tools and libraries your project is using. This will ultimately help you avoid versioning surprises and maintain a smoother development process.
While npm is widely used for managing development dependencies, several alternative tools offer support for development needs, such as handling large projects or enabling real-time updates.
Here’s a list of alternative tools to npm for installing devDependencies:
Learn how to manage dependencies using tools like npm, Yarn, and Nx by joining upGrad's Free Certificate Course, Introduction to Product Management.
Also Read: Yarn vs npm: Key Differences and How to Choose the Right Package Manager in 2025
Understanding the difference between dependencies and devDependencies will help you determine whether a package is needed for the application to run in production or only required during development.
Here’s how dependencies differ from devDependencies.
Dependencies | devDependencies |
Packages that are needed for the application to run in production. | These packages are only needed during the development phase. |
Used specifically in the runtime environment. | Used for testing, building, or linting the code. |
Included in the production build and deployed with the application. | Not part of the production build. It is used only during development. |
Installed with npm install <package> or added under "dependencies". | Installed with npm install <package> --save-dev or under "devDependencies". |
Examples: Express, Axios, and Lodash. | Examples: Mocha, Webpack, and ESLint. |
Now that you understand the difference between dependencies and devDependencies, let’s learn how to use npm scripts to enhance the development process.
You can automate repetitive tasks such as testing, building, and linting using npm scripts. As a developer, you can easily execute tasks with a single command by defining these scripts in the package.json file.
Here are some examples of npm scripts for the development process.
1. Test Script
It is used to automate running test cases. Here’s how the Test Script is defined in the package.json file:
"scripts": {
"test": "mocha"
}
You can run the Test Script with the following command:
npm run test
2. Lint Script
This script is used for automating code linting to ensure coding standards are followed. Here’s how Lint Script is defined in the package.json file:
"scripts": {
"lint": "eslint ."
}
You can run the Lint Script using the following command:
npm run lint
3. Build Script
The Build Script is used to automate the process of bundling or compiling code. Here’s how the Build Script is defined in the package.json file:
"scripts": {
"build": "webpack --mode production"
}
You can run the Build Script using the following command:
npm run build
Now, let’s explore how to update and remove unnecessary devDependencies using npm commands.
Regular updating ensures that the project is compatible with the latest features and security patches while removing unused dependencies, which makes the project lightweight and organized.
Here’s how you can update and remove devDependencies with npm commands.
1. Updating devDependencies
The following command updates to the latest compatible versions and saves the changes in the package.json file:
npm update --save-dev eslint webpack
2. Removing devDependencies
Removing unused devDependencies will keep the project lightweight. The following command removes the unnecessary dependencies and updates the package.json file:
npm uninstall @babel/core
Sometimes, your devDependencies become outdated, misaligned, or corrupted, especially if you’re working on a team or frequently switching environments. Reinstalling or bulk-updating these packages ensures everyone is on the same page and helps you avoid unexpected build or testing errors.
Let’s understand this through a step-by-step example demonstration.
Step 1: Check Your Current Dev Dependencies
Before you do any reinstallation or bulk updates, get a snapshot of what’s installed using this command:
npm list --dev
This helps confirm which devDependencies are currently present and their versions.
Step 2: (Optional) Remove node_modules and Lock Files
If you suspect major conflicts or corruption, the safest route is to start fresh using this command:
rm -rf node_modules
rm package-lock.json
Step 3: Reinstall All Dev Dependencies
Simply run this command:
npm install
npm install --only=dev
Step 4: Update Dev Dependencies
If you want to bring all devDependencies up to their latest compatible versions, use this command:
npm update --save-dev
npm update jest --save-dev
Step 5: Validate the Updated Environment
After everything reinstalls or updates, you must do the following things:
npm list --dev --depth=0
Why Do Reinstallation or Bulk Updates Matter?
By methodically removing old packages and then installing or updating them in bulk, you’ll maintain a reliable, up-to-date workspace that streamlines your development workflow.
You may face difficulty installing devDependencies due to specific environment settings or misconfigurations, such as package issues.
Here are some of the common reasons for failure and the solutions to overcome them:
In the production environment, devDependencies are usually excluded. You may need to include them explicitly using the --only=dev flag.
npm install --only=dev
If the --production flag is set to true, you may face difficulty in installing devDependencies. Set the flag to false during installation to include devDependencies.
npm install --production=false
A missing or corrupted package.json may prevent devDependencies from being installed. You need to verify the file or initialize a new npm package if required.
npm init -y
Installation can fail if there are conflicting dependencies or issues with the npm registry. You’ll have to clear the npm cache and retry.
npm cache clean --force && npm install
Even well-managed projects can face dependency or peer-dependency conflicts that prevent certain devDependencies from installing. In these scenarios, npm provides force-install flags to help override or bypass these restrictions, ensuring you can proceed without completely overhauling your setup.
Here’s a step-by-step guide on what you should do and how:
Step 1: Check Your Conflict Errors
Run a normal npm install or npm install --save-dev <package> to see the specific error messages. Identifying the exact conflict helps you decide whether forcing the installation is safe.
Step 2: Use the --force Flag
Apply --force (or -f) if you need to bypass version conflicts or warnings:
npm install <package> --force
This command compels npm to proceed with installation despite errors or peer-dependency warnings.
Step 3: Try --legacy-peer-deps for Peer-Dependency Issues
If the conflict arises from peer-dependencies, run this command:
npm install <package> --legacy-peer-deps
This tells npm to ignore modern peer-dependency enforcement rules, often resolving complex legacy setups.
Step 4: Validate Installation
Confirm that your devDependency is present using this command:
npm list --dev
If you still see errors or missing packages, check whether the forced install caused any unexpected version mismatches.
Step 5: Proceed with Caution
Forcing installations can create hidden version mismatches or break other packages. Always retest or rebuild after forcing an install to ensure everything works together as expected.
Also Read: How to Get List of Globally Installed Packages of npm
Efficient management of devDependencies will ensure a stable, secure, and maintainable project.
Here are some of the best practices that will optimize the development environment, avoid conflicts, and reduce unnecessary overhead in your projects:
An organized development environment helps maintain project performance, minimize errors, and enhance collaboration. Efficiently managing dependencies is key to achieving these goals.
Here are some tips to keep your development environment well-structured:
Also Read: Node JS Free Online Course with Certification [2025]
Development tools and devDependencies play a crucial role in ensuring efficient and high-performing projects. Mastering essential tools and techniques can open doors to promising careers in fields like DevOps and project management.
upGrad offers comprehensive courses in project management and DevOps that can help you prepare for roles in these fields.
Here are some courses of the most popular courses you can try:
Do you still need help deciding which courses can help you excel in DevOps? Contact upGrad for personalized counseling and valuable insights. For more details, you can also visit your nearest upGrad offline center.
Similar Blogs You Might Like:
Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.
Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.
Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.
Reference Link:
https://www.pmi.org/learning/careers/job-growth
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources