Last updated: May 25, 2023
Reading timeยท4 min
The npm warning "A requires a peer of B but none is installed. You must
install peer dependencies yourself" occurs because npm
no longer installs peer
dependencies automatically after version 3
.
To solve the issue install the second package from the error message with the
npm install --save-dev
command.
Here is the complete warning message.
For example, suppose that you got the following warning message:
In this case, you'd have to run the following command.
npm install --save-dev "typescript@>=2.7"
The package you should install as a dev dependency is specified in your warning message.
The format of the warning message is:
In this case, you have to run the following command.
npm install --save-dev "{PACKAGE_B}"
Notice that we install the second package from the error message.
Make sure to include the version in the installation command.
For example, suppose that you get the following warning message:
In this case, you have to run the following command.
npm install --save-dev "ajv@>=8"
The --save-dev
option installs the package in your development dependencies.
In other words, it adds the package to the devDependencies
object in your
package.json
file.
If the issue persists, try to install the latest version of the second package from the warning message.
For example, suppose that you get the following warning message:
Try to run the following command if the warning persists.
npm install --save-dev "ajv@latest"
npm
to the latest versionIf the issue persists, try to update npm
to the latest version.
Open your terminal and run the following command.
npm install -g npm@latest
If you get a permissions error on macOS or Linux, prefix the command with
sudo
.
sudo npm install -g npm@latest
If you get a permissions error on Windows, open CMD (Command Prompt) as an administrator and rerun the command.
npm install -g npm@latest
node_modules
directory and reinstall your modulesIf the issue persists, try to delete your node_modules
directory and reinstall
your modules.
If you are on macOS or Linux, open your terminal in your project's root
directory (where your package.json
) file is and run the following commands.
# 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
If you are on Windows, open CMD (Command Prompt) in your project's root directory and run the following commands.
# 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
--legacy-peer-deps
optionIf the issue persists, try to run the installation command with the
--legacy-peer-deps
option.
npm install --legacy-peer-deps
Or to install a specific package:
npm install axios --legacy-peer-deps
Make sure to replace axios
with the name of your specific package.
--legacy-peer-deps
flag ignores all peer dependencies when installing (in the style of npm
version 4 through 6).If the issue persists, you can ignore the warning messages.
Peer dependencies are listed in the package.json
file of some of the packages
you've installed.
Packages specify a peerDependencies
object in their package.json
file to set
which versions of other packages are compatible with this version of the
installed package.
If the specified versions of these packages are already present in your
node_modules
directory, no warnings are printed.
If the specified versions are not present in node_modules
, then they won't be
installed by NPM and a warning is printed.
The warning is also printed when you have other versions of the same packages installed.
You can just ignore these warnings as they most likely don't relate to you and
you either have other versions of the specified (peerDependencies
) packages
installed or you don't need them.
The peerDependencies
object is used to inform you which versions of other
packages are compatible with this version of the package in case you decide to
install these packages at a later point in time.
You can learn more about the related topics by checking out the following tutorials: