Introduction
When working with Node.js, you might need come throughout the npm ERR! code ETARGET. This error may be fairly irritating, particularly when it prevents you from putting in or updating your npm packages. Nonetheless, do not fret! On this article, we’ll discover what this error means, and how one can remedy it.
What’s the Error?
The npm ERR! code ETARGET
error sometimes occurs once you’re attempting to put in a model of a bundle that does not exist. Mostly, this occurs when there is a typo within the bundle title, a sort of the versioning syntax, or an issue along with your npm cache.
$ npm set up categorical@4.123.0
npm ERR! code ETARGET
npm ERR! notarget No matching model discovered for categorical@4.123.0.
npm ERR! notarget Normally you or one among your dependencies are requesting
npm ERR! notarget a bundle model that does not exist.
Fortunately the error message is definitely informative and tells you that the model you are attempting to put in would not exist. Within the instance above, we had been attempting to put in categorical
model 4.123.0
, which actually would not exist.
Checking Obtainable Module Variations
Step one I would suggest is to test the accessible variations of the module that you simply’re attempting to put in. You are able to do this utilizing the npm present
command:
$ npm present categorical variations
[
'0.14.0', '0.14.1', '1.0.0-beta', '1.0.0-beta2',
'1.0.0-rc', '1.0.0-rc2', '1.0.0-rc3', '1.0.0-rc4',
'1.0.0', '1.0.1', '1.0.2', '1.0.3',
...
'4.17.2', '4.17.3', '4.18.0', '4.18.1',
'4.18.2', '5.0.0-alpha.1', '5.0.0-alpha.2', '5.0.0-alpha.3',
'5.0.0-alpha.4', '5.0.0-alpha.5', '5.0.0-alpha.6', '5.0.0-alpha.7',
'5.0.0-alpha.8', '5.0.0-beta.1'
]
This command will show all of the accessible variations of the categorical
module. If the model you are attempting to put in is not listed, which means it would not exist, and you may want to put in a special model.
Verifying Bundle Spelling
As an instance you tried the above answer, however bought an error like the next:
$ npm present eexpress variations
npm ERR! code E404
npm ERR! 404 Unpublished by undefined on 2019-04-05T17:01:00.748Z
npm ERR! 404
npm ERR! 404 'eexpress' isn't within the npm registry.
npm ERR! 404 You must bug the writer to publish it (or use the title your self!)
npm ERR! 404
npm ERR! 404 Observe which you could additionally set up from a
npm ERR! 404 tarball, folder, http url, or git url.
(Discover I misspelled “categorical”)
On this case you could confirm the spelling of the bundle in your bundle.json
file (or on the command line). Typos occur to all of us, and npm will not be capable to discover a bundle that does not exist.
Open your bundle.json
file and test the spelling of the bundle inflicting the error. Ensure that it matches the official title on npm.
Clearing npm Cache
In case your bundle spelling is right and the model is within the npm present
command, then the subsequent step is to attempt clearing your npm cache. The npm cache is the place npm shops downloaded packages. Typically, this cache may cause issues, particularly if it incorporates outdated or corrupted packages.
$ npm cache clear --force
The above command will forcefully clear your npm cache. As soon as the cache is cleared, attempt putting in your bundle once more.
Updating the Bundle
If the model you are attempting to put in does exist, however you are still getting the error, it is perhaps that you could replace your bundle. You are able to do this utilizing the npm replace
command.
$ npm replace categorical
This command will replace the categorical
module to the most recent model. So as a substitute of counting on you to determine the precise (and actual) model, npm will do it for you. After operating this command, your bundle must be up to date, and the error must be resolved.
Eradicating node_modules and package-lock.json
Another choice that is perhaps a good suggestion is to take away any remnants of the problematic bundle out of your challenge. This contains the node_modules
listing and the package-lock.json
file.
$ rm -rf node_modules
$ rm package-lock.json
This fashion we all know we’re ranging from a clear state earlier than we try and reinstall the bundle.
Observe: It will take away all put in packages and the lock file. When you have different packages put in which might be working nice, you could need to simply delete the particular module listing beneath node_modules
. However clearing each is extra prone to remedy your downside.
Reinstalling the Bundle
With the node_modules
listing and package-lock.json
file out of the way in which, we will now attempt reinstalling the bundle.
$ npm set up
This command will fetch the packages listed in your bundle.json
file and set up them in a brand new node_modules
listing. It should additionally create a brand new package-lock.json
file. If the problematic bundle was simply having a foul day, this may remedy your challenge.
Conclusion
The npm ERR! code ETARGET No matching model discovered
error generally is a bit tough to unravel, however with a scientific method, it is undoubtedly manageable. We have gone by way of a number of steps to troubleshoot and repair this error, from clearing the npm cache and checking accessible module variations, to eradicating the node_modules
listing and package-lock.json
file, reinstalling the bundle, and verifying the bundle spelling. Hopefully, one among these strategies labored for you.