Using both moment and moment tz

11,509

Remove moment as a separate package in your package.json and reference moment-timezone whenever you need an instance of the moment object. In fact, if you don't and you're referencing both packages separately, you'll be loading two largely identical versions of moment.

The documentation referenced by @RobG in his comment is correct, it's just that the moment-timezone package itself loads moment as a dependency.

Share:
11,509

Related videos on Youtube

Scipion
Author by

Scipion

.

Updated on September 16, 2022

Comments

  • Scipion
    Scipion over 1 year

    I have recently added moment-timezone to my project. Now that I've started using it, I notice I have replaced nearly all my

    import * as moment from "moment" 
    

    with

    import * as moment from "moment-timezone" 
    

    I don't see any reason to keep moment around. Is there any limitation I should be aware of before removing it?

    • Jaromanda X
      Jaromanda X about 6 years
      do you use any of moment? we can't tell
    • Scipion
      Scipion about 6 years
      I do, but I was thinking about replacing all my moment by moment-timezone
    • Jaromanda X
      Jaromanda X about 6 years
      does importing moment-timezone give you access to moment functions? I don't think it does - I guess the question is, have you tried?
    • Scipion
      Scipion about 6 years
      yes I did, and it seems so, it's why I want to remove moment :)
    • RobG
      RobG about 6 years
      Read the documentation: "To use moment-timezone, you will need [email protected]+, moment-timezone.js, and the moment-timezone data."
  • Jeremy Wiebe
    Jeremy Wiebe over 4 years
    IMHO those docs could be more explicit that you only need to directly depend on one or the other, but not both. :)