I encountered an issue where my code works perfectly in localhost but fails in production, displaying the error
ERROR TypeError: n.endOf is not a function
import * as moment from 'moment';
changeMaxDate(maxTime: moment.Moment) {
if (maxTime) {
return maxTime.endOf('day').toISOString();
}
}
Despite extensive research on Moment questions and documentation, I have been unable to find a solution.
I have attempted various approaches, including using import moment from 'moment';
which also did not resolve the issue
Using Moment.js 2.24.0
TypeScript version 3.5.3
Angular version 8.2.3
<input matInput
[matDatepicker]="maxTime"
[(ngModel)]="data.maxTime"
(ngModelChange)="changeMaxDate(data.maxTime)"
placeholder="{{ 'yyyy-mm-dd' | translate }}">
<mat-datepicker-toggle matSuffix [for]="maxTime"></mat-datepicker-toggle>
<mat-datepicker #maxTime></mat-datepicker>
The maxTime extracted from the datepicker in localhost successfully displayed the Moment object:
Moment {_isAMomentObject: true, _i: {…}, _isUTC: false, _pf: {…},
_locale: Locale, …}
_d: Mon Nov 04 2019 23:59:59 GMT+0100 (Central European Standard Time)
__proto__: Object
_i: {year: 2019, month: 10, date: 4}
_isAMomentObject: true
_isUTC: false
_isValid: true
_locale: Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", _dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/, ordinal: ƒ, …}
_pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -1, charsLeftOver: 0, …}
__proto__: Object
However, in the production environment, it was converted into a string value:
Mon Nov 04 2019 00:00:00 GMT+0100 (Central European Standard Time)