Last updated: Apr 25, 2023
Reading timeยท6 min
Set the --production
flag to false
when issuing the npm install
command
to resolve the issue where npm install
doesn't install your
devDependencies
.
When the --production
flag is set to false
, npm will install all modules
listed in both dependencies
and devDependencies
.
npm install --production=false
You should also try to run the npm install
command with the --include
flag
set to dev
.
npm install --include=dev
Setting the --also
flag to dev
might also help.
# for older NPM versions npm install --also=dev
The most common reasons for npm not installing your devDependencies
are:
--production
flag is set to production
, npm won't install
modules listed in your devDependencies
object.NODE_ENV
environment variable is set to production
, npm won't
install modules listed in your devDependencies
.In order versions of npm
, you were able to only install devDependencies
by
setting the --only
flag to dev
npm install --only=dev
You can try running the command, however, in more recent versions, the available
options are null
, prod
and production
.
package.json
file is syntactically correctIf you have syntactical errors in your package.json
file, then the
npm install
command might not work as expected.
Make sure you have run the npm init -y
command and have initialized a
package.json
file in the root directory of your project.
npm init -y
The npm init -y
command won't override your existing package.json
file if
you already have one.
You can also change to another directory and initialize a new package.json
file by running the npm init -y
command to check if your existing file has
syntactical errors.
You can install a couple of modules manually and update your original
package.json
file.
# install multiple modules as dev dependencies npm install MODULE_A MODULE_B --save-dev
If you need to install a specific version of a module, use the @
symbol.
npm install MODULE_A@1.2.3 --save-dev
production
key in your NPM configAnother thing to check is that you haven't set the production
key in your NPM
config.
npm config get production
If the production
key is set to true
, then npm won't install the modules
listed in your devDependencies
.
You can disable the option by setting the key to false
.
npm config set production false
Make sure to set the key to false
in your global NPM config as well
npm config set --global production false
You can verify that the flag has been set to false
by issuing the following
commands.
# for user-specific NPM config npm config get production # for global NPM config npm config --global get production
You should either get a value of false
or null
when issuing the commands
above.
You can also use the npm config list
command to print your NPM configuration
keys and values.
npm config list
--save-dev
flagIf the issue persists, try to run the npm install
command with the
--save-dev
flag.
npm install --save-dev
You can also use the alias -D
which achieves the same result.
npm install -D
If you also have yarn
installed, you can run the yan install
command with
the --dev
flag.
yarn install --dev
If you need to install a specific module as a dev dependency, specify the module when issuing the command.
npm install axios --save-dev # same as above npm install axios -D
Make sure to replace axios
with the name of the package you're trying to
install as a development dependency.
The same can be achieved when using yarn
.
yarn add axios --dev
When the --save-dev
(or -D
) NPM flag or the --dev
flag of yarn
is
specified, the package is added to the devDependencies
object of your
package.json
file.
NODE_ENV
environment variable is not set to production
If your NODE_ENV environment variable is
set to production
, then NPM won't install the modules listed in your
devDependencies
.
You can check the value of your NODE_ENV
environment variable by issuing the
following command on macOS or Linux.
# ๐๏ธ Linux and macOS echo $NODE_ENV
If you are on Windows and use CMD, issue the following command instead.
# ๐๏ธ Windows with CMD echo %NODE_ENV%
If you are on Windows and use PowerShell, run the following command.
# ๐๏ธ on Windows with PowerShell echo $Env:NODE_ENV
If your NODE_ENV
variable is set to production
or prod
, you can unset it
by running the following command on macOS or Linux.
# on macOS and Linux unset NODE_ENV
If you are on Windows and use CMD, run the following command instead.
# on Windows with CMD set NODE_ENV=
If you are on Windows and use PowerShell, run the following commands.
[Environment]::SetEnvironmentVariable('NODE_ENV', '', 'User') [Environment]::SetEnvironmentVariable('NODE_ENV', '', 'Machine')
Try to rerun the npm install
command after clearing your NODE_ENV
environment variable.
If you don't want to change the value of your NODE_ENV
environment variable,
run the npm intsall
command with the --production
flag set to false
.
npm install --production=false
node_modules
and package-lock.json
filesThe issue is sometimes caused when your node_modules
directory and
package-lock.json
files are created using an older version of npm
.
One thing you can try is to delete the node_modules
folder and the
package-lock.json file and rerun
the npm install
command.
If you are on Windows, open your terminal in your project's root directory
(where your package.json
file is) and run the following commands in CMD.
# for Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force # ๐๏ธ install packages npm install # ๐๏ธ install packages npm install --save-dev
If you are on macOS or Linux, run the following commands in bash
or zsh
.
# for macOS and Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force # ๐๏ธ install packages npm install # ๐๏ธ install packages npm install --save-dev
Check whether your development dependencies have been installed successfully.
You can also try to restart your IDE and make sure you haven't hidden your node_modules folder from the left sidebar.
dependencies
with the --omit
flagIf you only want to install your dependencies
(and not your
devDependencies
), set the --omit
flag to dev
when running npm install
.
# only install dependencies and not devDependencies npm install --omit=dev
The command ignores the value of your NODE_ENV
environment variable and will
only install your dependencies
and not your devDependencies
.
If you use an older version of NPM (older than 6.0.0), you have to set the
--only
option to prod
to only install your dependencies
.
# for older NPM versions npm install --only=prod
When you run the npm install
command without specifying any flags, it installs
your dependencies
and devDependencies
, assuming the NODE_ENV
environment
variable is not set to production
.
# installs both dependencies and devDependencies npm install
You can learn more about the related topics by checking out the following tutorials: