components icon indicating copy to clipboard operation
components copied to clipboard

Can not add material to project using ng add @angular/material

Open landonwaldner opened this issue 8 years ago • 25 comments

Bug, feature request, or proposal:

Can not add material using schematic

What is the expected behavior?

Add material to project

What is the current behavior?

PS C:\Users\lando\test-project> ng add @angular/material Installing packages for tooling via npm. Collection "@angular/material" cannot be resolved. Error: Collection "@angular/material" cannot be resolved. at NodeModulesEngineHost._resolveCollectionPath (C:\Users\lando\test-project\node_modules@angular-devkit\schematics\tools\node-module-engine-host.js:88:15) at NodeModulesEngineHost.createCollectionDescription (C:\Users\lando\test-project\node_modules@angular-devkit\schematics\tools\file-system-engine-host-base.js:106:27) at SchematicEngine._createCollectionDescription (C:\Users\lando\test-project\node_modules@angular-devkit\schematics\src\engine\engine.js:78:40) at SchematicEngine.createCollection (C:\Users\lando\test-project\node_modules@angular-devkit\schematics\src\engine\engine.js:71:43) at Object.getCollection (C:\Users\lando\test-project\node_modules@angular\cli\utilities\schematics.js:28:31) at AddCommand.getOptions (C:\Users\lando\test-project\node_modules@angular\cli\models\schematic-command.js:193:41) at AddCommand. (C:\Users\lando\test-project\node_modules@angular\cli\commands\add.js:30:49) at Generator.next () at C:\Users\lando\test-project\node_modules@angular\cli\commands\add.js:7:71 at new Promise ()

What are the steps to reproduce?

ng new test-project --style scss --routing ng add @angular/material

What is the use-case or motivation for changing an existing behavior?

Having it work

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

"dependencies": { "@angular/animations": "^6.0.3", "@angular/common": "^6.0.3", "@angular/compiler": "^6.0.3", "@angular/core": "^6.0.3", "@angular/forms": "^6.0.3", "@angular/http": "^6.0.3", "@angular/material": "^6.3.0", "@angular/platform-browser": "^6.0.3", "@angular/platform-browser-dynamic": "^6.0.3", "@angular/router": "^6.0.3", "core-js": "^2.5.4", "rxjs": "^6.0.0", "zone.js": "^0.8.26" }, "devDependencies": { "@angular/compiler-cli": "^6.0.3", "@angular-devkit/build-angular": "~0.6.8", "typescript": "~2.7.2", "@angular/cli": "~6.0.8", "@angular/language-service": "^6.0.3", "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "codelyzer": "~4.2.1", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.0", "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.3.0", "ts-node": "~5.0.1", "tslint": "~5.9.1" }

Is there anything else we should know?

landonwaldner avatar Jun 19 '18 01:06 landonwaldner

Hey, I don't know what the fix is but by specifying to install the previous version angular/[email protected] and angular/[email protected] I was able to generate schematics successfully. judging from the fact 6.3.0 was updated 8 hours ago made me try the downgrade. I've pasted my package.json below:

{
  "name": "materialpoc",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/cdk": "^6.2.1",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/material": "^6.2.1",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.3",
    "@angular-devkit/build-angular": "~0.6.8",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.8",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

mohjache avatar Jun 19 '18 07:06 mohjache

As mentioned, angular material 6.3.0 seems broken, hope they will fix it soon, till now, downgrade to previous version (ex. 6.2.1 and install it from there)

lucferbux avatar Jun 19 '18 09:06 lucferbux

node_modules/@angular/material/schematics/collection.json Error: Invalid JSON character: " " at 29:49.

vladshut avatar Jun 19 '18 09:06 vladshut

Temp solution, use old version ng add @angular/[email protected]

FreakyMithril avatar Jun 19 '18 10:06 FreakyMithril

Facing same issue when running ng add @angular/material

mohaqqani avatar Jun 19 '18 16:06 mohaqqani

Facing the same issue. I've just used the old version @angular/[email protected] as temp solution

emmano3h avatar Jun 20 '18 15:06 emmano3h

mithril's suggestion worked for me. Thanks

ErikRobles avatar Jun 21 '18 02:06 ErikRobles

Experiencing the same thing.

ukon1990 avatar Jun 21 '18 10:06 ukon1990

https://github.com/angular/material2/issues/11844#issuecomment-398796341

Check this issue and see jelbourn comment.

fad250 avatar Jun 21 '18 13:06 fad250

Me too, but uamithril's solution below also worked for me

ng add @angular/[email protected]

SigmaOutdoors avatar Jun 21 '18 14:06 SigmaOutdoors

But is there any work around for:

ng generate @angular/material:material-nav --name="app-nav" Collection "@angular/material" cannot be resolved.

Once you have got 6.3.0 by using @latest ?

jimidle avatar Jun 22 '18 06:06 jimidle

better way just add old one ng add @angular/[email protected]

rohitgaidhane avatar Jun 22 '18 07:06 rohitgaidhane

same problem, I also tried "ng add @angular/[email protected]" but cdk doesnt install properly 6.3.0 or 6.2.1 anyway.

herbalizer404 avatar Jun 22 '18 09:06 herbalizer404

I had to run the following to get it to work:

npm install --save @angular/[email protected] @angular/[email protected]
ng add @angular/[email protected]

roger-walker avatar Jun 22 '18 17:06 roger-walker

Downgrade the cli version to 6.0.0 and try ng add @angular/[email protected]

TharinduRangana avatar Jun 23 '18 13:06 TharinduRangana

The issue might be that you aren't specifying a project name. I was able to run ng add @angular/material --project=<myProjectName> without error.

iamtracy avatar Jun 23 '18 17:06 iamtracy

@TharinduRangana @iamtracy It's actually because the schematics file has a missing quotation mark. #11839 fixes this.

EdricChan03 avatar Jun 24 '18 04:06 EdricChan03

Facing the same issue. I've just used the old version @angular/[email protected] and @angular/[email protected] as temp solution

swamytalam avatar Jun 24 '18 15:06 swamytalam

editing ./node_modules/@angular/schematics/collection.json to remove the redundant aliases (and thus also fixing the missing quote) works.

bluppfisk avatar Jun 27 '18 13:06 bluppfisk

As @bluppfisk mentioned, editing the collection.json FIXES the issue on the latest version of Material. For convenience, here's the updated file:

Replace ./node_modules/@angular/material/schematics/collection.json with:

// This is the root config file where the schematics are defined.
{
  "$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
  "schematics": {
    // Adds Angular Material to an application without changing any templates
    "ng-add": {
      "description": "Adds Angular Material to the application without affecting any templates",
      "factory": "./install",
      "schema": "./install/schema.json",
      "aliases": ["material-shell"]
    },
    // Create a dashboard component
    "dashboard": {
      "description": "Create a card-based dashboard component",
      "factory": "./dashboard/index",
      "schema": "./dashboard/schema.json",
      "aliases": ["material-dashboard"]
    },
    // Creates a table component
    "table": {
      "description": "Create a component that displays data with a data-table",
      "factory": "./table/index",
      "schema": "./table/schema.json",
      "aliases": ["material-table"]
    },
    // Creates toolbar and navigation components
    "nav": {
      "description": "Create a component with a responsive sidenav for navigation",
      "factory": "./nav/index",
      "schema": "./nav/schema.json",
      "aliases": [ "material-nav" ]
    },
    // Creates a address form component
    "addressForm": {
      "description": "Create a component with a address form",
      "factory": "./address-form/index",
      "schema": "./address-form/schema.json",
      "aliases": ["address-form"]
    }
  }
}

BirdInTheCity avatar Jun 29 '18 16:06 BirdInTheCity