[Resolved] npm install not installing dev dependencies

How to fix issue with NPM install not installing the devDependencies

Jun 21, 2023 | Read time 4 minutes

🔔 Table of contents


When you run npm install in your project directory, npm should install both the dependencies and devDependencies specified in your package.json.

If this is not happening, there could be a few possible reasons:

Running NPM install under production mode

NODE_ENV is set to production: npm will not install modules listed in devDependencies if the NODE_ENV environment variable is set to production.

You can check your current environment variable by running:

echo $NODE_ENV

If it outputs production, you need to unset it or set it to development.

To unset it in Linux/Mac:

unset NODE_ENV

Or to set it to development:

export NODE_ENV=development

The –production flag is being used: The –production flag will prevent devDependencies from being installed. Make sure you’re not using this flag if you want to install devDependencies.

Check package-lock.json is out of sync with package.json

package-lock.json or yarn.lock file is out of sync: Sometimes, these files might be out of sync with your package.json. You can try deleting package-lock.json (and node_modules/, just to be safe), then run npm install again.

To delete node_modules and package-lock.json, you can use:

rm -rf node_modules
rm package-lock.json

Then run npm install again.

Review package.json issues

There’s an issue with the specific package: If only a specific package listed in devDependencies is not being installed, there might be an issue with that specific package. It could be that the package is not available, or there’s a typo in the package name or version.

  • The package is not available: It’s possible that a package was removed from the npm registry, or never existed in the first place. For example, if your devDependencies include a package named nonexistent-package, running npm install will give you an error because this package doesn’t exist.

  • There’s a typo in the package name: Package names need to be exact. If there’s a typo in the package name in your devDependencies, npm won’t be able to find it. For example, if you’re trying to install the package express but you’ve accidentally written expres, npm won’t find the package.

  • The specified version is not available: In your devDependencies, you might have specified a version of a package that doesn’t exist. For example, if you’re trying to install version 1.2.3 of a package, but the latest version is 1.2.2, npm won’t be able to install it.

Your package.json might look like this:

  "devDependencies": {
    "some-package": "^1.2.3"

In this case, you can find out the latest available version of the package on the npm registry and correct it in your package.json.

  • The package is not compatible with your system or npm/node version: Some packages are only compatible with specific versions of node or npm, or specific operating systems. If you’re trying to install a package that’s not compatible with your environment, it might fail to install.

Clear cache, node_modules folder, package-lock.json files and reinstall

One option that worked well for NPM issues for me is to nuke the whole project - removing node_modules and reinstall everything.

To do this we can use the steps, open up the terminal and make sure you are in the root directory of the project:

  1. npm install -g npm@latest to update npm because it is sometimes buggy.
  2. rm -rf node_modules to remove the existing modules.
  3. Run npm cache clean --force to make sure we don’t have random modules from the cache.
  4. Execute npm install to re-install the project dependencies.

👋 About the Author

G'day! I am Huy a software engineer based in Australia. I have been creating design-centered software for the last 10 years both professionally and as a passion.

My aim to share what I have learnt with you! (and to help me remember 😅)

Follow along on Twitter , GitHub and YouTube