Home > Software engineering >  ERR! notarget No matching version found for elements@~0.1.2
ERR! notarget No matching version found for elements@~0.1.2

Time:07-01

I'm fairly new to angular and I'm trying to install packages by running 'npm install' but getting this error and am unsure how to resolve:

npm ERR! notarget No matching version found for elements@~0.1.2. npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist.

Here's my Package.json:

{
  "name": "securities-onboarding-ui",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "prepush": "npm run build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~12.1.2",
    "@angular/common": "~12.1.2",
    "@angular/compiler": "~12.1.2",
    "@angular/core": "~12.1.2",
    "@angular/forms": "~12.1.2",
    "@angular/platform-browser": "~12.1.2",
    "@angular/platform-browser-dynamic": "~12.1.2",
    "@angular/router": "~12.1.2",
    "bootstrap": "^4.6.0",
    "crypto-js": "^4.1.1",
    "elements": "~0.1.2",
    "ng-multiselect-dropdown": "^0.3.8",
    "rxjs": "~6.6.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~12.1.2",
    "@angular/cli": "~12.1.2",
    "@angular/compiler-cli": "~12.1.2",
    "@types/crypto-js": "^4.1.1",
    "@types/jasmine": "~3.8.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.8.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "tslib": "^2.3.1",
    "typescript": "~4.3.2"
  }
}

elements is a package in an Azure Devops feed defined with the below dependencies:

Dependencies
  tslib ^1.9.0
  
Peer dependencies
  @angular/common ^8.2.14
  @angular/core ^8.2.14
  bootstrap ^4.5.0
  jquery ^3.5.1

angular version:

Angular CLI: 13.2.0
Node: 16.13.2
Package Manager: npm 8.1.2
OS: win32 x64

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1302.0 (cli-only)
@angular-devkit/build-angular   <error>
@angular-devkit/core            13.2.0 (cli-only)
@angular/cli                    13.2.0 (cli-only)
@schematics/angular             13.2.0 (cli-only)
rxjs                            6.6.7 (cli-only)
typescript                      <error>

What am I missing here? Please help. Let me know if you need any more info

CodePudding user response:

The error is corresponding to the entry inside dependencies array in package.json file :

"elements": "~0.1.2"

The error indicates that the mentioned version does not exist on npm repo anymore

Every component in the package.json follow the naming convention : major.minor.patch

npm uses the tilde (~) and caret (^) to designate which patch and minor versions to use respectively.

So if you see ~0.1.2 it means to install version 0.1.2 or the latest patch version such as 0.1.4. If you see ^0.1.2 it means to install version 0.1.2 or the latest minor or patch version such as 0.2.2 etc.

I think you should first check on the npm repo which version you want or you can try updating package.json with ^ instead of ~ in front of the elements version.

Please let me know how it will go.

CodePudding user response:

Thank you to all who contributed toward the solution.

Turns out my issue was caused by the fact that I had 2 registries in my .npmrc file, namely https://registry.npmjs.org and a private one by my workplace team (Prior to this I didn't know only 1 registry can be used, not both).

I was trying to access 'elements 0.1.2' in the private registry however npm was instead reading the package from npmjs.org which is named 'elements 0.6.0'. I discovered this by running the command 'npm view elements' and got the below:

[email protected] | MIT (http://mootools.net/license.txt prime dom library http://mootools.net dist .tarball: https://registry.npmjs.org/elements/-/eleme

So when I tried running 'npm install', npm couldn't find version 0.1.2 that I had specified in my package.json, hence the error. To resolve, I republished the package in our private registry as a scoped package in order to be able to have 2 registries in my .npmrc file, and that basically solved the issue.

To give you an idea of my solution:

In package.json: "@companyName/elements": "^0.1.2"

In .npmrc:

@companyName:registry=https://pkgs.dev.azure.com/xx/Group/_packaging/xxx/npm/registry/ 
always-auth=true
//pkgs.dev.azure.com/xx/xx/_packaging/xx/npm/registry/:username=xx
//pkgs.dev.azure.com/xx/xx/_packaging/xx/npm/registry/:_password=xx
//pkgs.dev.azure.com/xx/xx/_packaging/xx/npm/registry/:email=xx
//pkgs.dev.azure.com/xx/xx/_packaging/xx/npm/:username=xx
//pkgs.dev.azure.com/xx/xx/_packaging/xx/npm/:_password=xx
//pkgs.dev.azure.com/xx/xx/_packaging/xx/npm/:email=xx
registry=https://registry.npmjs.org
  • Related