moment-timezone: Property 'tz' does not exist on type 'Moment' Error
nodejs version: 12.18.4
moment-timezone version: 0.5.31
moment version: ^2.29.0
ts-node version: happens both in 9.0.0(latest), 8.6.2
command: ts-node --files server/app.ts --project server/tsconfig.build.json
usage
import moment from 'moment-timezone'
moment(somedate).tz(sometimezone)
No @types/moment or @types/moment-timezone
installed since deprecated.
What could be the reason ?
PS: Already checked this Issue
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 15 (1 by maintainers)
Commits related to this issue
- update import moment issues https://github.com/moment/moment-timezone/issues/906 — committed to dimaslanjaka/static-blog-generator by dimaslanjaka a year ago
- update import moment issues https://github.com/moment/moment-timezone/issues/906 — committed to dimaslanjaka/static-blog-generator by dimaslanjaka a year ago
This issue re-occured again with the following versions:
Downgrading moment to 2.29.2 fixes the issue.
Edit: Another way to fix things for good is to get rid of
moment
and rely completely onmoment-timezone
, you don’t need to use both.Using the latest version at this time of writing:
moment-timezone@0.5.33
and@types/moment-timezone@0.5.30
I do not have the issue:moment().tz('CEST')
<- no errors…So I think this is issue is resolved.
I resolved this by downgrading the
moment-timezone
package to0.5.28
(instead of0.5.31
).I found that the offending lines in
0.5.31
with my setup are:index.d.ts
:This is generally caused by having multiple versions of
moment
imported at the same time, due to different dependency trees. I’ve written a full description at https://github.com/moment/moment-timezone/issues/982#issuecomment-1119540905As noted by @DiRover, importing from only
moment-timezone
should fix the issue in most cases.The same issue with versions:
Downgraded to 2.29.1, but it contains vulnerabilities.
Solved by @gilmoreorless comments. Changed my import to
import moment, { tz } from "moment-timezone";
And working codeconst timeOffset = moment().tz(timezone).format("Z")
i sove this problem
2.import time-zone in app.component.ts file import ‘moment-timezone’;
3.save and run
-check some moment-timezone package version not work
I’m having exactly the same issue.
node version:
12.14.1
moment version:2.24.0
moment-timezone version:0.5.31
ts-node version:8.3.0
Usages:
They yield same result: