Details
Description
SYMPTOM:
Can't download the asset after removing one version of an NPM component from a NPM hosted repository.
REPRODUCE STEPS:
- Create a npm hosted repository: npm-hosted
- Create and publish "mytest" with version 1.0.0, 1.1.0, 1.2.0
# Change below to your Nexus npm hosted repository URL: _NXRM_URL="http://dh1:8081/repository/npm-hosted" mkdir -v mytest; cd mytest cat << EOF > ./package.json { "author": "nxrm test", "description": "reproducing issue", "keywords": [], "license": "ISC", "main": "index.js", "name": "mytest", "publishConfig": { "registry": "${_NXRM_URL}" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "version": "1.0.0" } EOF for i in {0..2}; do sed -i.tmp -E 's/"version": "1.[0-9].0"/"version": "1.'${i}'.0"/' ./package.json npm publish --registry "${_NXRM_URL}" -ddd || break sleep 1 done cd -
- Make sure "npm pack mytest" downloads v1.2.0
npm pack mytest --registry "${_NXRM_URL}"
- From your browser, go to mytest/mytest-1.2.0.tgz, and click [ Delete asset ], or delete with curl
curl -u admin:admin123 -X DELETE ${_NXRM_URL%/}/mytest/-/mytest-1.2.0.tgz
- Try "npm pack mytest" again
npm cache clean --force npm pack mytest --registry "${_NXRM_URL}"
EXPECTED BEHAVIOUR:
The "npm pack mytest" should download v1.1.0.
NPM package metadata MUST ALWAYS have a latest tag according to package metadata docs, the full package metadata format, under the dist-tags section , "Every package will have a latest tag defined"
ACTUAL BEHAVIOUR:
npm ERR! code ETARGET npm ERR! notarget No matching version found for mytest@latest. npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist. npm ERR! A complete log of this run can be found in: npm ERR! /home/testuser/.npm/_logs/2021-11-08T05_15_16_193Z-debug.log
Also, the dist-tags in the metadata is empty:
POTENTIAL CAUSE:
When an asset is deleted from a NPM component, can't find any metadata recreate method such as NpmPackageRootMetadataUtils#createFullPackageMetadata is used.