Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to resolve the 'tz' build error. #385

Closed
redmember opened this issue Sep 21, 2016 · 17 comments
Closed

How to resolve the 'tz' build error. #385

redmember opened this issue Sep 21, 2016 · 17 comments

Comments

@redmember
Copy link

redmember commented Sep 21, 2016

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.
   }
}
...
@joelbanzatto
Copy link

Same issue here.

Property 'tz' does not exist on type 'typeof moment'.

@MingyuJeon
Copy link

Does anyone solve this issue now?

@wceolin
Copy link

wceolin commented Dec 23, 2016

@MingyuJeon Installing @types/moment-timezone should solve this issue:

npm i @types/moment-timezone --save-dev

@damsorian
Copy link

the @types/moment-timezone not works for me :(

@Gizrah
Copy link

Gizrah commented Apr 10, 2017

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();

@nickion
Copy link

nickion commented May 10, 2017

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.

@damsorian
Copy link

damsorian commented May 10, 2017

I resolved this issue using moment.tz(myDate, myTimezone) instead of myDate.tz(myTimezone)

Also using @types/moment-timezone

@vincebanzon
Copy link

vincebanzon commented Sep 5, 2017

since we are both using angular, this is how I did it.

npm install moment-timezone -S

import moment from "moment-timezone";

@BMalaichik
Copy link

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

@inlightmedia
Copy link

inlightmedia commented Jan 11, 2018

I could not import moment-timezone@0.5.14 with moment@2.20.1. 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'; 

@ghost
Copy link

ghost commented May 27, 2018

With 2018 typescript use:

npm install @types/moment-timezone -S
import * as moment from 'moment';
import 'moment-timezone';

@Raju
Copy link

Raju commented Nov 27, 2019

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

@rtp4jc
Copy link

rtp4jc commented Jun 23, 2020

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';

@Pronoy999
Copy link

The solution is:
Add these in the Package.json
"@types/moment": "^2.13.0",
"@types/moment-timezone": "^0.5.30",
"moment": "^2.27.0",
"moment-timezone": "^0.5.31",

Then in the relevant file:

import moment from "moment";
import "moment-timezone";

After this you can use moment and tz functions.

@carlosananias
Copy link

já que ambos estamos usando angular, foi assim que fiz.

npm install moment-timezone -S

import moment from "moment-timezone";

this worked well for me!

@ismaelguerrib
Copy link

The solution is: Add these in the Package.json "@types/moment": "^2.13.0", "@types/moment-timezone": "^0.5.30", "moment": "^2.27.0", "moment-timezone": "^0.5.31",

Then in the relevant file:

import moment from "moment"; import "moment-timezone";

After this you can use moment and tz functions.

This is the only solution that works for me !

@gilmoreorless
Copy link
Member

You shouldn't need to import both moment and moment-timezone — one already imports the other. Importing both could be causing problems if there are multiple versions of a dependency in your project. See #982 (comment) for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests