moment-timezone: Do not log error when requiring moment-timezone multiple times in Node

In Node it is quite common to require a module in multiple places

Right now if I require moment-timezone in multiple places I am getting

Moment Timezone 0.4.0 was already loaded with data from 2015d

That comes from this line (#212 )

This shouldn’t be logged as an error and just clutters the server logs. If anything, it should be a warning but in Node env it shouldn’t be printed at all IMO

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 4
  • Comments: 42 (8 by maintainers)

Most upvoted comments

Seriously, just remove the useless console.log line. I can’t even do it in a fork, moment-timezone is a dep of other libraries i’m using. Here’s what i have to do right now, this is ridiculous

const oldConsoleLog = console.log;
console.log = () => {};
import Agenda from 'agenda';
console.log = oldConsoleLog;

This is polluting our logs, could you change from ‘error’ to ‘warning’ please?

still not fixed?

It’s been almost a year, maybe we could remove the console.log polluting logs in the meantime?

Also getting this…

+1

+1

I’m getting this as well. Sequelize has moment-timezone as a dependency and almost certainly that causes the issue.

This is a pretty big pain for me, as the logging library used on an e-commerce project I am tasked with fixing suffers from this issue, so none of the logs have dates or times. It is insanely difficult for me to track down which logs occurred when to match logs to observed behavior in the system at the time they were observed.

At this time, I am reduced to sitting and waiting for the error to happen again to see exactly which logs are written, which means I am literally waiting for this company to lose more money. Can this be prioritized in any way? If you have not completed a fix, but have completed your reorganization, can it be placed in a branch so that the community (myself included) can try to complete the fix ourselves without stepping on your work?

I would also consider this a bug versus an enhancement; it prevents usage.

Another month

I’m able to reproduct this problem if i install the package rschmukler/agenda, because it depends on moment-timezone@0.5.0 and cron@0.1.0 -> which in turn depends on moment-timezone@0.3.1.

+1

Making the loading idempotent as suggested by @mj1856 and @antoniopironti would be ideal imo.

We’re still having this problem. We use moment-timezone inside of our app, but the ORM sequelize also uses moment-timezone internally. So we get this error.

What exact problems come from two different apps requiring moment? Can that problem still occur when a moment-timezone is loaded inside both the application and a dependency?

No problem, and glad to hear you got it working! 😄