I'm using moment.js
to change the local date format for my application but getting the following error:
"moment" has no exported member 'default' when importing the library.
Below is my code:
import {Inject, Injectable, Optional} from '@angular/core';
import {DateAdapter, MAT_DATE_LOCALE, MatDateFormats} from '@angular/material';
import * as _moment from 'moment';
import {default as _rollupMoment, Moment} from 'moment';
const moment = _rollupMoment || _moment;
Try adding "allowSyntheticDefaultImports": true
to your tsconfig.json
under the "compilerOptions"
You seems to have trouble importing moment
As you can see in the documentation,
For Typescript 2.x try adding "moduleResolution": "node"
in compilerOptions
in your tsconfig.json
file and then use any of the below syntax:
import * as moment from 'moment';
import moment = require('moment');
PS: Make sure you have installed moment.js
with npm
:
npm install --save moment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With