moment / moment-timezone

Timezone support for moment.js
momentjs.com/timezone
MIT License
3.82k stars 835 forks source link

import moment from 'moment-timezone'; import 'moment/min/locales'; not working #1078

Closed rendomnet closed 9 months ago

rendomnet commented 10 months ago

Environment

{ "moment": "2.29.4", "momentTz": "0.5.43", "date": "Sat Oct 28 2023 16:45:48 GMT+0600 (East Kazakhstan Time)", "intlZone": "Asia/Almaty" }

Issue description

import moment from 'moment-timezone';
import 'moment/min/locales';

the locales do not load. But if I use

import moment from 'moment';
import 'moment/min/locales';

then it works

gilmoreorless commented 10 months ago

Usually situations like this are caused by accidentally having 2 different copies of moment somewhere in the dependency tree. See the "npm" and/or "yarn" sections at https://github.com/moment/moment-timezone/issues/982#issuecomment-1119540905 for tips to verify if that's the problem (and how to fix it).

rendomnet commented 10 months ago

@gilmoreorless I have only this

    "moment": "^2.29.4",
    "moment-timezone": "^0.5.43",
gilmoreorless commented 10 months ago

What's specified in package.json is only part of the story. As https://github.com/moment/moment-timezone/issues/982#issuecomment-1119540905 explains, what matters is how the dependencies are actually installed in node_modules. moment-timezone could be depending on a version of moment that's different from the one you've specified.

This is something I'm hoping to solve by moving moment to be a peer dependency of moment-timezone (https://github.com/moment/moment-timezone/issues/1039#issuecomment-1445251204).

rendomnet commented 10 months ago

I've completely removed the 'node_modules' directory and reinstalled it, but the issue still persists. Do I need to have "moment" for 'moment-timezone' to have the necessary locale files? Are they compatible?

gilmoreorless commented 9 months ago

If there's a lockfile like package-lock.json or yarn.lock that's storing the duplicate versions, removing node_modules won't fix the problem. I've already linked to better explanations of how to diagnose and fix this.