Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using moment with Angular 18

After upgrading to Angular 18 I get following error when using moment.

Calling "moment" will crash at run-time because it's an import namespace object, not a function

My import statement looks as following

import * as moment from 'moment';

using moment looks like this

moment(this.to.val, this.validTimeFormats, true).isValid()

Any help?

like image 936
faebzz Avatar asked Jun 21 '26 14:06

faebzz


1 Answers

When updating to version 18 angular adds esModuleInterop to the tsconfig.json

https://www.typescriptlang.org/tsconfig/#esModuleInterop

According to documentation either remove it or import moment as

import moment from 'moment';
like image 65
Andrej Piecka Avatar answered Jun 23 '26 03:06

Andrej Piecka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!