1

As mentioned in the question's title I can't enable material design although I'be followed the official documentation.
I did the following steps:
npm install --save @angular/material
npm install --save @angular/animations
and this is my package.json file:

"dependencies": {
    "@angular/animations": "^4.2.5",
    "@angular/cdk": "github:angular/cdk-builds",
    "@angular/common": "^2.4.0",
    "@angular/compiler": "^2.4.0",
    "@angular/core": "^2.4.0",
    "@angular/forms": "^2.4.0",
    "@angular/http": "^2.4.0",
    "@angular/material": "github:angular/material2-builds",
    "@angular/platform-browser": "^2.4.0",
    "@angular/platform-browser-dynamic": "^2.4.0",
    "@angular/router": "^3.4.0",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.1.0",
    "zone.js": "^0.7.6"
  },

So everything is perfectly installed but right now I'm facing two problems:
The first one is that the compiler can't find the animations module when I try to import BrowserAnimationsModule:
enter image description here The second problem is that when I import material modules in NgModule like this:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    MdButtonModule,
    MdMenuModule,
    MdCardModule,
    MdToolbarModule,
    MdIconModule
  ],
  providers: [

  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

I get this error in the console, and a bunch of warning messages:
enter image description here

What am I missing here ?

1
  • 2
    You're using @angular dependencies with mixed versions (4.2.5, 2.4.0), which are thus not compatible with each other. Use the latest stable version of angular, and use the same version for all the @angular dependencies. Commented Jul 1, 2017 at 8:35

2 Answers 2

3

Angular 4 uses InjectionToken instead of OpaqueToken which is used by Angular 2 and as you are mixing your @angular dependency versions between the two you get a bunch of errors stating that the InjectionToken cannot be found.

What I suggest is if this is a new project you can update node/npm by downloading Node.js from here and then you update the Angular CLI to the latest version by following those steps:

Step 1: run this command to uninstall the old CLI

npm uninstall -g @angular/cli
npm cache clean

Step 2: install the CLI globally

npm install -g @angular/cli@latest

If this is a big Angular 2 project you can follow this guide to refactor it to an Angular 4 project.

Sign up to request clarification or add additional context in comments.

3 Comments

you're right sir it was an angular CLI problem, after updating it everything works fine now :).
@Slimen glad this helped you! really happy to see a tunisian joining the angular community!
npm cache clean is now changed to npm cache verify as of npm 5
2

In your package.json, try to replace "@angular/material": "github:angular/material2-builds",

with

 "@angular/material": "^2.0.0-beta.7",

Your @angular/animations is version ^4.2.5 while the other modules @angular/core, compiler etc is version 2.4.0. Try to update those as well to 4.2.5

Also, try to delete the node_modules in your root folder and run npm install again. Everything else seems fine with the code you provided. Hope this helps

8 Comments

@SlimenTunis I updated my answer. I didn't notice your animations version is different with your @angular/core and etc.
but I have installed these dependencies using angular CLI so it will install the last version of each dependency right ?
If you are using ^ in your package, it will update to minor updates. Take a look at this docs.npmjs.com/getting-started/semantic-versioning. Again to be sure, delete your node_modules and run npm install again it usually solves my problem
oh ok this make sense, I will re-install all the dependencies using the same version.
@SlimenTunis let me know if you still have problems
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.