Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"moment" has no exported member 'default'

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;
like image 294
Amit Golhar Avatar asked Feb 19 '19 12:02

Amit Golhar


2 Answers

Try adding "allowSyntheticDefaultImports": true to your tsconfig.json under the "compilerOptions"

like image 78
dileepkumar jami Avatar answered Oct 20 '22 21:10

dileepkumar jami


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
like image 6
veben Avatar answered Oct 20 '22 21:10

veben