• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Install Dev Dependencies With npm

Thumbnail for Mansi ManhasMansi Manhas

Mansi Manhas

Published: 1/31/2024

About Terminus

Dev dependencies are packages required only for the development phase and not for the application to run in production. Some common examples of such packages are testing frameworks (jest, cypress, karma, mocha), code linters (prettier, eslint), build tools (babel, webpack), and more.

The short answer

To install one or more npm packages as dev dependencies, you can use the npm install command combined with the --save-dev flag as follows:

$ npm install <package_name …> --save-dev

Run in Warp

For example:

$ npm install jest eslint --save-dev

Run in Warp

Alternatively, you can use the shorthand -D flag (short for development):

$ npm install <package_name> -D

Run in Warp

All the npm packages you add using the above flags will be found under the devDependencies section in package.json and automatically installed in the node_modules folder of your project.

Thumbnail for

Easily retrieve this command using Warp’s AI Command Search

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Thumbnail for

Entering npm install dev dependencies in the AI Command Search will prompt an npm command that can then quickly be inserted into your shell by doing CMD+ENTER.

Installing a specific package version

By default, the npm install command installs the latest version of the specified packages. If you want to install a specific version instead, you can use @ followed by the package's version number.

For example:

$ npm install jest@^27.0.0 --save-dev 

Run in Warp

Installing dev dependencies using the package.json

Suppose you want to add multiple packages with specific versions, then adding the package names and versions in the package.json file would be easier than manually installing each package using the npm install <package_name> command.

"devDependencies": {
  "eslint": "^7.7.0",
  "eslint-config-prettier": "^6.9.0",
  "jest": "^29.4.2"
}

Run in Warp

Once the package.json file is updated, you can run the npm install command to automatically install all the packages listed under the dependencies and devDependencies sections in the node_modules folder.

$ npm install

Run in Warp

Installing dev dependencies only

To install only the dev dependencies, you can use the npm install command followed by the --only=dev flag:

$ npm install --only=dev

Run in Warp

Troubleshooting common dev dependency installation issues

If you cannot install the devDependencies, cross-check the value of the NODE_ENV environment variable (commonly used in the Node.js environment). If this value is set to production, then npm will skip the installations of packages listed under the devDependencies. Thus, ensure that the value for NODE_ENV is set to development.

To verify the value of the NODE_ENV variable, you can use the echo command as follows:

$ echo $NODE_ENV

Run in Warp

To set or update the value of the NODE_ENV variable, you can use the export command as follows:

$ export NODE_ENV=development

Run in Warp

Alternatively, you can use the following syntax, to locally set the NODE_ENV variable as development everytime you execute the npm install command, ensuring that both production and development dependencies are installed. 

$ NODE_ENV=development npm install

Run in Warp

Reinstalling dev dependencies

Reinstalling or updating or all npm packages follows the same process and commands for both dependencies and devDependencies. Read more about how to reinstall all packages with npm

To update or re-install only the dev dependencies, you must use the --save-dev flag. This command will update the already installed dev dependencies according to the version ranges defined in the package.json file.

$ npm install --save-dev

Run in Warp

To update a specific package to the latest version regardless of the version specified in the package.json file, use the npm install command followed by the package name:

$ npm install <package_name> --save-dev 

Run in Warp

Alternatively, you can use the npm update command as well: 

$ npm update --save-dev
$ npm update <package_name> --save-dev

Run in Warp

Troubleshooting cache issues when updating already installed packages

NPM maintains a cache of downloaded packages to speed up the installations. If you encounter any installation issues, consider clearing the npm cache by using the npm cache command:

$ npm cache clean --force

Run in Warp

Written by

Thumbnail for Mansi ManhasMansi Manhas

Mansi Manhas

Filed Under

Related Articles

Removing npm Packages

Learn how to remove packages locally, globally, and from the registry using the npm uninstall command.

Npm
Thumbnail for Utsav PoudelUtsav Poudel

Execute Packages With npx And npm

Discover the power of npm's npx tool, a developer's best friend for running packages without global installs.

Npm
Thumbnail for Glory KimGlory Kim

Clear npm Cache

Learn how to clear the npm cache on Linux, macOS, and Windows.

NpmLinux
Thumbnail for Razvan LudosanuRazvan Ludosanu

How To Update NPM

Learn how to update npm to a specific version using the npm, nvm, or npx commands.

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

Re-Installing Npm

Learn how to reinstall Node.js and npm on macOS, Linux, and Windows using `curl`, `brew`, `apt`, `nvm`, and Node installer.

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

How To Reinstall Packages With Npm

Brief guide to reinstalling npm packages using npm

Npm
Thumbnail for Glory KimGlory Kim

Check Npm Package Version

Check an npm package version within your project

Npm
Thumbnail for Glory KimGlory Kim

Install NPM Packages From GitHub

Check an npm package version within your project

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

List Installed Npm Packages

Learn how to list globally and locally installed packages with npm, including their dependencies.

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for null