This article is more than 1 year old

At the very last Moment.js: Time-and-date JavaScript library fetched 12 million times a week ends development

Programmers put decade-old package out to pasture, advise devs to find alternatives

The maintainers of Moment.js, a JavaScript time-and-date handling library downloaded 12 million times a week, put the project into maintenance mode on Tuesday, and advised developers to consider alternatives.

"We recognize that many existing projects may continue to use Moment, but we would like to discourage Moment from being used in new projects going forward," a project status update read this week. "We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done."

That means there will be no new features, API changes, performance improvements, or major changes. There will be security fixes and data updates related to IANA time zone database changes, though the idea is to wean apps from Moment.js if possible.

Moment's time in the sun ended a few years ago when developers started warning about its downsides.

And a recent Twitter post by Google Chrome engineering manager Addy Osmani may have helped push the Moment maintainers to abandon ship. Three days ago, he announced that Lighthouse, a performance measurement application that's part of Chrome's developer tools, has been updated to spot bloated libraries and suggest lighter-weight alternatives.

Moment.js is the only JavaScript library under the glare of Lighthouse at the moment, though Osmani said Lodash, a popular JavaScript library best known these days for security problems, will be the next one to get marked by Chrome's scarlet console letters.

Developers discussing the matter on Twitter aren't all enthusiastic about Google shaming underfunded open-source projects for size, performance, or other supposed shortcomings.

"This is going to be an incredibly toxic tool that is weaponized against already overburdened maintainers," wrote Tierney Cyren, senior cloud developer advocate at Microsoft, a sentiment shared by other coders.

At the same time, one of Moment's maintainers, Maggie Johnson-Pint, senior software engineering lead at Microsoft, appears to have taken Google's hectoring in her stride.

In answer to Cyren's tweeted concerns about Lighthouse's unsolicited recommendation, she said, "I've said this a few times, but as the maintainer in question in this case – good, move on to a modern library. Moment was a huge emotional pain for all of its maintainers until we accepted the reality that people could move on, and that actually didn't impact us one bit."

What's the problem with Moment.js? JavaScript programmers dislike the fact its code doesn't work with tree-shaking, a process for pruning unneeded code when bundling multiple JavaScript files into a single file. That means production apps relying on the library are likely to have large bundles of code to download and to perform poorly.

Also, the library makes Moment objects mutable, meaning the use of methods like addition and subtraction change not only the variable receiving the assignment but value in the original object.

For example:

var a = moment('2016-01-01'); 
var b = a.add(1, 'week'); 

Both the variable b and a were changed in the assignment process, which can create problems if not expected or not worked around using the clone method.

Moment's maintainers acknowledge this is a common source of complaints, though they say that making Moment objects immutable would break backwards compatibility.

It's that commitment to legacy stability over modernization that signals Moment cannot last. Changes to browsers, browser engines, or other aspects of web architecture may require adaptations in open source browser-oriented code, work that volunteer projects may not want or be able to undertake.

In response to Osmani's Lighthouse announcement, developer Sunil Pai suggested that Google should do more to fund renovation work on open source projects if it's going to be endorsing particular projects.

Osmani said he agrees.

"Chrome currently has a yearly web performance and frameworks fund for sponsoring work like this," he said. "We’ve been working with OpenCollective to expand on this for 2021 and will have more funding to announce soon."

In the meantime, Moment maintainers suggest Luxon, Day.js, date-fns, js-Joda, or built-in JavaScript objects as alternatives. ®

More about


Send us news

Other stories you might like