32
votes

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

8
Do you have '@angular/material-moment-adapter' in node_modules?Dmitry Grinko
Seems like you need to import { MatMomentDateModule } from '@angular/material-moment-adapter' and import MatMomentDateModule in app.module.ts. hope this will fix itNick B
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

8 Answers

14
votes

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 [email protected]

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 [email protected]

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

62
votes

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 )

30
votes

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

npm i @angular/material-moment-adapter
10
votes

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.

3
votes

Just run this CMD

npm i @angular/material-moment-adapter

If it shows any error install

npm i moment
2
votes

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.

0
votes

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.

0
votes

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.