Error below :
ERROR in [default] /home/myubuntu/work/angular_cli_webpack/src/app/app.log.component.ts:264:31
Property 'tz' does not exist on type 'Moment'.
[environment]
angular2: 2.0.0
angular-cli webpack : 1.0.0-beta.14
moment": "^2.14.1
moment-timezone": "^0.5.5
[angular-cli.json]
...
......
"scripts": [
"../node_modules/moment/moment.js",
"../node_modules/moment-timezone/builds/moment-timezone-with-data-2010-2020.min.js",
"../node_modules/locomote-video-player/dist/locomote.min.js"
],
......
...
[app.log.component.ts]
import * as moment from 'moment';
import 'moment-timezone';
...
...
class AppLogComponent {
constructor() {}
public func() {
var utc_time = moment.utc(unix_tm_sec*1000);
var camera_time = utc_time.tz(timezone); <--- error position.
}
}
...
Same issue here.
Property 'tz' does not exist on type 'typeof moment'.
Does anyone solve this issue now?
@MingyuJeon Installing @types/moment-timezone should solve this issue:
npm i @types/moment-timezone --save-dev
the @types/moment-timezone not works for me :(
I somehow got it to work as this:
npm install moment moment-timezone --save --global
Then in the relevant file:
import moment from "moment";
import "moment-timezone";
...
let timezone = moment.tz.guess();
We came across this and it was because the package maintainers had created a breaking change by removing the 2010-2020 file and replacing it with 2012-2022 rather than adding a new file for the different time range.
I resolved this issue using moment.tz(myDate, myTimezone) instead of myDate.tz(myTimezone)
Also using @types/moment-timezone
since we are both using angular, this is how I did it.
npm install moment-timezone -S
import moment from "moment-timezone";
May help somebody:
Faced issue using local own npm package, which had dependency on @types/moment-timezone, but no imports was done with from "moment-timezone", but package consumer - had
So, as a result type casting failed since dependency used moment(because of no imports), but package consumer - moment-timezone
I could not import [email protected] with [email protected]. They were apparently incompatible.
However, changing moment to version 2.18.1 fixed it for me.
I used this import syntax:
import moment from 'moment';
import 'moment-timezone';
With 2018 typescript use:
npm install @types/moment-timezone -S
import * as moment from 'moment';
import 'moment-timezone';
You need to update the dependencies tz-offset module from version 0.0.1 to version 0.0.2
Here is the link for tz-offset module,
https://www.npmjs.com/package/tz-offset
It looks like the @types/moment-timezone package has been deprecated according to #858
I fixed it by uninstalling that package and using this code (from above):
import * as moment from 'moment';
import 'moment-timezone';
Most helpful comment
@MingyuJeon Installing
@types/moment-timezoneshould solve this issue:npm i @types/moment-timezone --save-dev