Visual Studio Code error TS2305 with moment.js example from angular material design tutorial

node_modules/moment/moment"' has no exported member 'default'.
node_modules/moment/moment''' has no default export
moment default value
utc not found in imported namespace moment

I tried the following code from https://material.angular.io/components/datepicker/overview#choosing-a-date-implementation-and-date-format-settings (see below). It complies and I can run the code but I get an error in visual studio code which says that 'default is not an exported member of moment. I am using Visual Studio Code 1.24.1

import { default as _rollupMoment} from 'moment';

ERROR in src/app/component.ts(20,10): error TS2305: Module '"../frontend/node_modules/moment/moment"' has no exported member 'default'.

import {Component} from '@angular/core';
import {FormControl} from '@angular/forms';
import {MAT_MOMENT_DATE_FORMATS, MomentDateAdapter} from '@angular/material-moment-adapter';
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';

// Depending on whether rollup is used, moment needs to be imported differently.
// Since Moment.js doesn't have a default export, we normally need to import using the `* as`
// syntax. However, rollup creates a synthetic default module and we thus need to import it using
// the `default as` syntax.
import * as _moment from 'moment';
// tslint:disable-next-line:no-duplicate-imports
import {default as _rollupMoment} from 'moment';

const moment = _rollupMoment || _moment;

/** @title Datepicker that uses Moment.js dates */
@Component({
  selector: 'datepicker-moment-example',
  templateUrl: 'datepicker-moment-example.html',
  styleUrls: ['datepicker-moment-example.css'],
  providers: [
    // `MomentDateAdapter` and `MAT_MOMENT_DATE_FORMATS` can be automatically provided by importing
    // `MatMomentDateModule` in your applications root module. We provide it at the component level
    // here, due to limitations of our example generation script.
    {provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
    {provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS},
  ],
})
export class DatepickerMomentExample {
  // Datepicker takes `Moment` objects instead of `Date` objects.
  date = new FormControl(moment([2017, 0, 1]));
}

I left away the second import statement for moment as proposed in Importing moment into Angular gives error. Now it works...

Managing Dates and Times Using Moment.js, I left away the second import statement for moment as proposed in Importing moment into Angular gives error. Now it works Angular is a popular JavaScript library for building web application user interfaces developed by Google. The Visual Studio Code editor supports Angular IntelliSense and code navigation out of the box. We'll be using the Angular CLI for this tutorial. To install and use the command line interface as well as run the Angular application server

I just commented out the second statement as follows:

import * as _moment from 'moment';
// import { default as _rollupMoment} from 'moment';
// const moment = _rollupMoment || _moment;
const moment = _moment;

[Pro User] No exported member, Visual Studio Code error TS2305 with moment.js example from angular material design tutorial - angular. Once Angular CLI is installed successfully, open VS Code and navigate to View >> Integrated Terminal. This will open the terminal window, as shown in the image below. Type the following sequence of commands in the terminal window.

I have the same error. Then I change my code like this:

import * as moment from 'moment';
type Moment = moment.Moment;
const moment1 = moment;

export class AppComponent {
date = new FormControl(moment1());
}

And it works.

Hope this helps.

Angular Material DatePicker (with MomentJs Integration), Hi,I on index.ts file, under node_modules/ng-mdb-pro, the error belowError:(2, 9) TS2305: Module '../node_modules/ng-mdb-pro/free/index' has no exported  Passing each angular material component i.e checkbox, button etc in app.module.ts is very tedious so we can create new module using following command Ng g m shared\material –flat(this will create shared folder and material.module.ts)

Note: If you have trouble importing moment, try adding "allowSyntheticDefaultImports": true in compilerOptions in your tsconfig.json file and then use the syntax

https://momentjs.com/docs/#/use-it/typescript/

it worked for me :)

Building web apps powered by Angular 2.x using Visual Studio 2017, In this lesson, we are going to show the Angular Material DatePicker component in so that it Duration: 4:41 Posted: Mar 15, 2018 Visual Studio Code TypeScript and Html snippets and code examples for Angular 2,4,5,6, 7 & 8 Beta. The source for the snippets come from: and most of all, none of this would exist without the help of all the contributers for fixing, enhancing, testing and making suggestions.

5 Steps to add Moment.js to Angular CLI - jek.bao.choo, Can we get the source code of the sample banking project you created in Using visual studio 2017, no options for creating angular project with authentication? TS2305: Module '"E:/SkyDrive/_PROJECTS/Web Projects/​Angular2 0x800a138f - JavaScript runtime error: Unable to get property 'apply' of  All Angular snippets starts with "ng-". Multiple snippets come in multiple variations. For instance when you want to create a new component you can choose between having the template and css inline or not: ng-component-inline. ng-for currently has even more variations, so make sure you pick the one you want before you press enter: Angular Material.

Typescript : How to resolve 'rxjs/Rx has no exported member ', In this guide, we are adding Moment.js to Angular (application platform). It is worth noting… Literature Review: Moment.js Vs. date-fns Vs. Luxon. “Moment.​js has in JavaScript. Usable with Angular Material's datepicker. Material Design components for Angular. Sprint from Zero to App. Hit the ground running with comprehensive, modern UI components that work across the web, mobile, and desktop. Fast and Consistent. Finely tuned performance, because every millisecond counts. Fully tested across modern browsers. Themeable, for when you need to stay on brand or

I faced the same issue after following. Following this tutorial from djamware. After searching a lot, I have found that Rxjs package that is  This tutorial describes how to setup the Angular 4 project in Visual studio 2015 from scratch. It includes all the details starting from installing nodejs, typescript tools for visual studio 2015

Comments
  • See also stackoverflow.com/questions/49301355/…
  • Hi! I have the same problem. I don't understand exactly what you did here to make it work...