npm ERR! code ETARGET No matching version found for [Fixed]

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# npm ERR! code ETARGET No matching version found for [Fixed]

The error "npm ERR! code ETARGET No matching version found for X" occurs for multiple reasons:

  • Running the npm install command when your package.json file contains a package set to an invalid or unavailable version.
  • Running the npm install package@version command with an invalid version.
  • Having stale cache issues.
  • Misspelling the name of the package.

npm err code etarget no matching version found

shell
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.

# Clearing the cache

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.

shell
npm cache clean --force

clear the npm cache

After you clear the cache, try installing your npm modules.

shell
npm install

# Viewing the available module versions

If the error persists, look at your error message and make note of the package that causes it.

For example, "No matching version found for axios@" means that the version of 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.

shell
npm view axios versions

list package 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.

shell
npm install axios@1.3.4

install specific version of package

The syntax for installing a specific version is npm install package@version.

Make sure to replace the package and version with your specific package and a version you picked from the output of the 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:

  1. Issue the npm view <package> versions command.
  2. Manually update the version of the package in your package.json file.
package.json
{ "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.

# Installing the latest version of the package

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.

shell
npm install axios@latest

install specific version of package

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.

shell
npm install axios@latest --force

install using force option

# Run the npm update command

If you still get the error, run the npm update command.

shell
npm update

run npm update command

The npm update command respects semver. It updates the packages with a fuzzy version to the latest version and installs missing packages.

# Delete your node_modules and package-lock.json files

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).

cmd
# 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.

shell
# 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:

  1. Delete your node_modules directory and your package-lock.json file.
  2. Clear the cache.
  3. Reinstall your dependencies.

# Try to uninstall the package and then install it

If the error persists, try to uninstall the package and then install it.

shell
npm uninstall axios

uninstall package first

Make sure to replace axios with your specific package.

Try to reinstall the package afterward.

shell
npm install axios

reinstall package

# Make sure you haven't misspelled the package

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.

# Conclusion

To solve the error "npm ERR! code ETARGET No matching version found for X", make sure:

  • Your package.json file doesn't contain unavailable or non-existent versions of packages.
  • To install only versions of packages that exist with the npm install package@version command.
  • To clear your cache.
  • You haven't misspelled the name of the package.
I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.