Last updated: Apr 4, 2024
Reading time·4 min
The error "npm ERR! code ETARGET No matching version found for X" occurs for multiple reasons:
npm install
command when your package.json
file contains a
package set to an invalid or unavailable version.npm install package@version
command with an invalid version.npm ERR! code ETARGET npm ERR! notarget No matching version found for axios@1.3.5. npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist.
The first thing you should try is to clear the cache.
The version of the package might be available but your cache might be stale.
Open your terminal and issue the following command.
npm cache clean --force
After you clear the cache, try installing your npm
modules.
npm install
If the error persists, look at your error message and make note of the package that causes it.
axios
we are trying to install doesn't exist.You can use the npm view <package> versions
to get a list of the available
versions for the given package.
npm view axios versions
Make sure to replace axios
with the name of the package that caused the error
in your case.
You can pick a specific version of the package from the list and install it.
npm install axios@1.3.4
The syntax for installing a specific version is npm install package@version
.
npm view
command.Running the npm install
command will automatically update the contents of your
package.json
file.
An alternative approach to solving the error is to:
npm view <package> versions
command.package.json
file.{ "name": "bobbyhadz-react", "dependencies": { "axios": "^1.3.4" } }
However, this isn't necessary because running the npm install package@version
command automatically updates your package.json
file.
An alternative way to solve the error is to install the latest version of the package.
Open your terminal in your project's root directory (where your package.json
file is) and run the following command.
npm install axios@latest
Make sure to replace axios
with the name of your specific package.
The syntax for the command is npm install package@latest
.
The command looks up the latest available version of the package and installs it.
If you get an error when issuing the command, try to rerun it with the --force
option.
npm install axios@latest --force
npm update
commandIf you still get the error, run the npm update
command.
npm update
The npm update
command respects semver. It updates the packages with a fuzzy
version to the latest version and installs missing packages.
If the error persists, try to delete your node_modules and
package-lock.json (NOT
package.json
) files.
On Windows, issue the following commands from the root directory of your project
(where your package.json
file is).
# on Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # 👇️ clean your npm cache npm cache clean --force npm install
On macOS and Linux, issue the following commands from the root directory of your project.
# on macOS and Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # 👇️ clean your npm cache npm cache clean --force npm install
The commands:
node_modules
directory and your package-lock.json
file.If the error persists, try to uninstall the package and then install it.
npm uninstall axios
Make sure to replace axios
with your specific package.
Try to reinstall the package afterward.
npm install axios
Another common cause of the error is misspelling the package you are trying to install.
Make sure the package is spelled correctly when issuing the npm install
command.
To solve the error "npm ERR! code ETARGET No matching version found for X", make sure:
package.json
file doesn't contain unavailable or non-existent versions
of packages.npm install package@version
command.