The npm ETARGET
error can be solved in two ways:
- Replace the version requirement of the problematic package in your
package.json
file - Install the latest version of the problematic package with the
npm install [package]@latest
command.
Let’s learn how to do both in this tutorial.
The ETARGET error explained
When you run the npm install
command, npm will work to install the packages you defined as dependencies in your package.json
file.
Sometimes, you might see an error with code ETARGET
as shown below:
$ npm install
npm ERR! code ETARGET
npm ERR! notarget No matching version found for vue@^2.8.0.
npm ERR! notarget
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are
npm ERR! notarget requesting a package version that doesn't exist
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'n-app'
npm ERR! notarget
The error ETARGET
means that npm can’t find a package version that matches your requirements as defined in the package.json
file.
In the case above, the error is caused by the vue
package. In your project, the problematic package may be different.
The package.json
file that causes the error is as follows:
{
"name": "n-app",
"version": "1.0.0",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"axios": "^0.27.2",
"vue": "^2.8.0",
"webpack": "^5.73.0"
}
}
This means there is no vue
package between v2.8.0 and v3.0.0 available from the npm registry.
You can check the available versions of a package using the npm view [package] versions
command:
# 👇 check available vue versions
npm view vue versions
To fix the ETARGET
error, you need to replace the version requirements written in the dependencies
section with the one that’s available from npm.
Here’s an example:
{
"dependencies": {
"axios": "^0.27.2",
"vue": "^3.2.37",
"webpack": "^5.73.0"
}
}
Save the changes, and run the npm install
command again. It will work this time.
Alternatively, you can also choose to install the latest stable version of the package with npm install [package]@latest
command.
Here’s an example:
# 👇 install the latest stable vue package
npm install vue@latest
npm will install the latest stable vue
version, then automatically update the dependencies
section of the package.json
file.
And that’s how you resolve the npm ERR! code ETARGET issue. Good work! 👍