0

When I tried adding the Material library to my angular project by running npm install --save @angular/material @angular/cdk, I ran into the problems described in this question: Error TS2315: Type 'ElementRef' is not generic material angular

So following the advice there, I ran npm install -g @angular/cli@latest; now, all ng commands yield the following:

$ ng Unknown error: Error: schema with key or id "http://json-schema.org/draft-06/schema" already exists

ng works from other folders, so I guess something is now broken within the project. How can this be fixed?

Searching for this error message didn't yield anything useful and the project's json files (like tsconfig.json) all look fine.

package.json:

{
  "name": "some-frontend",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.0.1",
    "@angular/cdk": "^6.0.1",
    "@angular/common": "6.0.1",
    "@angular/compiler": "6.0.1",
    "@angular/core": "6.0.1",
    "@angular/forms": "6.0.1",
    "@angular/http": "6.0.1",
    "@angular/material": "^6.0.1",
    "@angular/platform-browser": "6.0.1",
    "@angular/platform-browser-dynamic": "6.0.1",
    "@angular/router": "6.0.1",
    "core-js": "^2.4.1",
    "npm": "^6.0.1",
    "rxjs": "^6.1.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "6.0.1",
    "@angular/compiler-cli": "6.0.1",
    "@angular/language-service": "6.0.1",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "2.7.2"
  }
}

Previous package.json file:

{
  "name": "some-frontend",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "~1.7.4",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}
Philipp Ludwig
  • 3,758
  • 3
  • 30
  • 48
  • What version of the CLI were you on before you installed the @latest version, which is now 6.0.1? What version of Angular are you running? What version of material and cdk were installed? – R. Richards May 12 '18 at 14:05
  • No clue, I'm always just following the guidelines on the angular website which instruct to use ``@latest``. Material and cdk weren't installed before. I*ve installed CLI a few days ago on this system though, so it can't be far apart from 6.0.1. – Philipp Ludwig May 12 '18 at 14:06
  • It seems by the error that the versions of the libraries are out or alignment. Can you edit your post to include the project's *package.json*? – R. Richards May 12 '18 at 14:17
  • Sure, I've included the file's contents. – Philipp Ludwig May 12 '18 at 14:19
  • That actually looks right. Was this an existing project, or did you start this new from `ng new`? If it was an existing project, try running `ng update @angular/cli`, if you can. – R. Richards May 12 '18 at 14:25
  • It was an existing project. Running ``ng update @angular/cli`` yields the same error message sadly. I've checked out a previous version of the project, running ``ng update @angular/cli`` seems to do nothing then. I've found the old ``package.json`` file though and included it in the question, we can now see that the CLI version was ancient. – Philipp Ludwig May 12 '18 at 14:28
  • Not really an ancient version. That was the latest before they jumped to 6.0.0 to match the Angular Core version. Only other thing I can think to try is uninstall/verify cache/reinstall the CLI. Do that by following the steps in the *Global package* section [here](https://github.com/angular/angular-cli#updating-angular-cli). Outside of that, I am a bit stumped. Good luck! – R. Richards May 12 '18 at 14:37
  • Sadly that didn't do anything. Thanks for your help, maybe someone else has an idea. – Philipp Ludwig May 12 '18 at 14:41

2 Answers2

2

It seems that this was caused by packages which haven't been installed completely/wrong. Running

npm install --save

caused npm to complain about broken files; after removing those, the installation completed successfully.

Then however ng complained about the file angular.json being missing; this can be fixed by migrating properly, as described in a related question:

ng update @angular/cli --migrate-only --from=1.7.4
Philipp Ludwig
  • 3,758
  • 3
  • 30
  • 48
1
rm -rf /node_modules

and after that installing the packages again by

npm install

worked for me.

René Winkler
  • 6,508
  • 7
  • 42
  • 69