29

Why is this not working? I try importing the MomentDateAdapter as shown on the angular website but Visual Studio Code keeps complaining it cant find @angular/material-moment-adapter. What am I doing wrong?

version info: Angular CLI: 1.5.0 Node: 6.11.0 OS: darwin x64 Angular: 4.4.6 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router, tsc-wrapped

@angular/cdk: 2.0.0-beta.12 @angular/cli: 1.5.0 @angular/material: 2.0.0-beta.12 @angular-devkit/build-optimizer: 0.0.32 @angular-devkit/core: 0.0.20 @angular-devkit/schematics: 0.0.35 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.8.0 @schematics/angular: 0.1.1 typescript: 2.3.4 webpack: 3.8.1

Curtis
  • 2,383
  • 4
  • 24
  • 38
  • Do you have '@angular/material-moment-adapter' in node_modules? – Dmitry Grinko Dec 14 '17 at 14:59
  • 2
    Seems like you need to `import { MatMomentDateModule } from '@angular/material-moment-adapter'` and import `MatMomentDateModule` in app.module.ts. hope this will fix it – Nick B Dec 14 '17 at 16:13
  • I do not have @angular/material-moment-adapter in my node_modules. I have @angular/language-service, @angular/material, @angular/platform-browser. No @angular/material-moment-adapter. – Curtis Dec 14 '17 at 17:05

8 Answers8

59

For those, like me, that also reached this question and already have the lastest @angular 5+.

Don't forget to install Moment.js: npm i moment (as I did )

xudre
  • 2,491
  • 2
  • 16
  • 17
27

Just run this command using npm for installing @angular/material-moment-adapter:

npm i @angular/material-moment-adapter
insertusernamehere
  • 21,742
  • 7
  • 80
  • 113
M.Shafiq Tahir
  • 371
  • 3
  • 3
13

Since @angular/material-moment-adapter requires Angular v5 and up and was only introduced recently (in 5.0.0-rc0), you have to update your dependencies as follows:

npm install -s @angular/{animations,common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router}@'^5.0.1' rxjs@'^5.5.2'
npm install -E typescript@2.4.2

Adapted from https://update.angular.io

EDIT:

Note: As of NPMJS 5, you no longer have to specify the --save flag as this is the default option (see this blog post on changes to NPMJS 5 for more info (under the breaking changes section)):

npm i @angular/{animations,common,compiler,core,forms,platform-browser,platform-browser-dynamic,router}@latest rxjs@latest moment
npm i -D typescript@2.9

(P.S. The -D flag is an alias of --save-dev)

Edric
  • 18,215
  • 11
  • 68
  • 81
  • ran the first command got back a bunch of lines like this: "@angular/animations@5.1.1 invalid" and "UNMET PEER DEPENDENCY @angular/compiler@5.1.1 invalid" – Curtis Dec 18 '17 at 15:53
  • I was having issues running those commands but based on what you said about angular 5 being required I used the now updated CLI to generate a new project and copied the package.json file from the fresh project over and that seemed to work. – Curtis Dec 19 '17 at 19:37
  • 2
    Down voter, could you explain why you downvoted this answer? – Edric Apr 05 '18 at 10:57
  • 1
    @Edric: I think it would be nice to extend your answer (because this one is the accepted) with the importance of adding moment.js as [xudre wrote it below](https://stackoverflow.com/questions/47816319/cannot-find-module-angular-material-moment-adapter#answer-50711379) – Burnee Sep 07 '18 at 19:55
  • @Burnee Thanks for the heads up! I've added what you've said in my answer. – Edric Sep 08 '18 at 06:16
  • Yeah this is not enough. – Mulperi Nov 14 '18 at 06:16
  • @Mulperi Could you clarify? – Edric Nov 14 '18 at 08:48
9

Check out this: https://stackblitz.com/angular/gxamabemnyx

Something to note you will have to manually install the module: npm install @angular/material-moment-adapter

Looking at the package.json it's missing.

tallgeese117
  • 176
  • 2
2

run the command ctrl + c for terminate. Then run again ng serve to re-run the application. after that, you can see the following image. enter image description here

The issue is here. The moment js

Then run the command to install moment.js by running following common in application location.

npm i moment

After that, you can see it's installed as in the following image.

enter image description here In my case, the issue was correct by these steps.

Sandun Susantha
  • 438
  • 2
  • 5
2

Just run this CMD

npm i @angular/material-moment-adapter

If it shows any error install

npm i moment
Sushil
  • 158
  • 1
  • 5
0

Easiest step I can think of would be go to your npm package, right click and delete, and run command in git bash in project folder - npm install. Installation will proceed. Other option is cd into your c drive, and run npm list -g which will list all the modules you got in global setting, you would try to find the one that you are missing in this question. Third option, if nothing works blow away your global node module and re-install it. Instruction on how to do so is already answered in this link below.
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
Dominic Tancredi has answered it so well. he has mentioned about how to do so in Mac, you would remove sudofrom commands that he has mentioned to make it work in Windows.

surendrapanday
  • 349
  • 1
  • 11
0

You must intall in @angular 5+

  1. moment.js npm i moment

2.Material Moment Adapter npm i @angular/material-moment-adapter

Here is the link You can visit here.