Moment-timezone: Module 'moment' has no exported member 'MomentFormatSpecification'

Created on 23 May 2016  Â·  16Comments  Â·  Source: moment/moment-timezone

I'm trying to use moment-timezone in the browser. Installed it like this using typings 1.0.4:

typings install dt~moment-timezone -SG

The resolved typings\globals\moment-timezone\index.ts file ends up with these lines that is causing TS build failure:

    (date: string, format: moment.MomentFormatSpecification, timezone: string): moment.Moment;
    (date: string, format: moment.MomentFormatSpecification, strict: boolean, timezone: string): moment.Moment;
    (date: string, format: moment.MomentFormatSpecification, language: string, timezone: string): moment.Moment;
    (date: string, format: moment.MomentFormatSpecification, language: string, strict: boolean, timezone: string): moment.Moment;

Is this a bug or am I doing something wrong?

TypeScript

Most helpful comment

It worked!
I had to :
typings uninstall -SG moment moment-node moment-timezone
then:
typings install -SG dt~moment-timezone dt~moment

thanks @wceolin

All 16 comments

I have the same problem. The issue is probably that the moment-timezone typescript bindings are not up to date with moment typescript bindings.

See #341 for TBD on adding typescript bindings for moment-timezone. We'd certainly accept a pull request.

What is pull request number?

I need it for typings.

For now a workaround that let me get past this is:

typings install --global dt~moment-node dt~moment-timezone

angular2 & typescript newb here. thanks @konrad-garus for providing that workaround. I gave that a try and it seems to install. However, I get the following run-time error so something still ain't right:

> zone.js:101 GET http://localhost:4200/moment-timezone 404 (Not Found)scheduleTask @ zone.js:101ZoneDelegate.scheduleTask @ zone.js:336Zone.scheduleMacroTask @ zone.js:273(anonymous function) @ zone.js:122send @ VM1796:3fetchTextFromURL @ system.src.js:1154(anonymous function) @ system.src.js:1735ZoneAwarePromise @ zone.js:584(anonymous function) @ system.src.js:1734(anonymous function) @ system.src.js:2759(anonymous function) @ system.src.js:3333(anonymous function) @ system.src.js:3600(anonymous function) @ system.src.js:3985(anonymous function) @ system.src.js:4448(anonymous function) @ system.src.js:4700(anonymous function) @ system.src.js:406ZoneDelegate.invoke @ zone.js:323Zone.run @ zone.js:216(anonymous function) @ zone.js:571ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256drainMicroTaskQueue @ zone.js:474ZoneTask.invoke @ zone.js:426
> zone.js:461 Unhandled Promise rejection: Error: XHR error (404 Not Found) loading http://localhost:4200/moment-timezone
>       at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:4200/vendor/zone.js/dist/zone.js:769:30)
>       at ZoneDelegate.invokeTask (http://localhost:4200/vendor/zone.js/dist/zone.js:356:38)
>       at Zone.runTask (http://localhost:4200/vendor/zone.js/dist/zone.js:256:48)
>       at XMLHttpRequest.ZoneTask.invoke (http://localhost:4200/vendor/zone.js/dist/zone.js:423:34)
>   Error loading http://localhost:4200/moment-timezone as "moment-timezone" from http://localhost:4200/app/flight-reports/timeline/timebar.component.js ; Zone: <root> ; Task: Promise.then ; Value: Error: Error: XHR error (404 Not Found) loading http://localhost:4200/moment-timezone(…)consoleError @ zone.js:461_loop_1 @ zone.js:490drainMicroTaskQueue @ zone.js:494ZoneTask.invoke @ zone.js:426
> zone.js:463 Error: Uncaught (in promise): Error: Error: XHR error (404 Not Found) loading http://localhost:4200/moment-timezone(…)

For what it's worth I'm importing it as follows (though not sure if it's right):

import * as moment from 'moment';
import 'moment-timezone';

I've also installed the package via npm as follows:

npm install -g moment-timezone

Do I need to add it manually to system-config.ts? to main.ts? Any other ideas why it doesn't just work?

thanks in advance for any wisdom you may be able to impart,
Rob

@berkeleydiego Looking at your stacktace, the error is really a 404 on http://localhost:4200/moment-timezone.

I don't know what there is in your stack, how everything is packaged and served (and it doesn't look familiar at the first glance). So I don't know the answer, the only idea is to understand what's trying to load moment-timezone from this location (maybe it shouldn't?) or how to provide it to the loader so it doesn't 404 (when it should indeed be loaded).

I have almost the same problem:

node_modules/@types/moment-timezone/index.d.ts(31,39): error TS2305: Module 'moment' has no exported member 'MomentFormatSpecification'.
node_modules/@types/moment-timezone/index.d.ts(32,39): error TS2305: Module 'moment' has no exported member 'MomentFormatSpecification'.
node_modules/@types/moment-timezone/index.d.ts(33,39): error TS2305: Module 'moment' has no exported member 'MomentFormatSpecification'.
node_modules/@types/moment-timezone/index.d.ts(34,39): error TS2305: Module 'moment' has no exported member 'MomentFormatSpecification'.

Only in my case, the types were installed from npm @types/moment-timezone with typescript v2.0. Actually it's the same, but when I used npm package typings and installed them from dt, I didn't face this issue.

I had problems with @types (in another package) because a package was 2 weeks old. Maybe it is the same issue, they don't sync very often.

@AndreiShostik did you solve this issue? I'm facing almost the same problem installing from @types/moment-timezone.

@wceolin yep, I've created custom typing file moment.d.ts with current content:

import * as moment from "moment";

declare module "moment" {
    export type MomentFormatSpecification = string;
}

export = moment;

you may also have to add it in tsconfig.json depending on what files are compiled

@AndreiShostik thanks, as moment-timezone also imports moment itself, I ended up solving my issue importing it as import * as moment from 'moment-timezone';

As @wceolin and @AndreiShostik I also use the import from moment-timezone
The problem is that it relies on moment-node typings and this became deprecated.

deprecated 8/29/2016: "registry:dt/moment-node#2.11.1+20160511043338" is deprecated (updated, replaced or removed)

Our build is strict and thus is failing now.
I didn't find a way to have newer typings, moment-node disappeared from api.typings.org

@titimoby since RC.6, I'm using @types/moment and @types/moment-timezone (with angular-cli@webpack). It's working fine.

It worked!
I had to :
typings uninstall -SG moment moment-node moment-timezone
then:
typings install -SG dt~moment-timezone dt~moment

thanks @wceolin

@AndreiShostik This solved my issue. Checked the files source code, there isn't any type definition for MomentFormatSpecification in the current version. This pull request seemingly fixed the issue. Is there a pull request here as well?

Edit: The issue seems to be fixed in https://github.com/moment/moment/commit/0866ff94f3cf02f1a7b885daec2b4ad2e045301a

This issue should be closed.

Closing since several people are saying fixed.

Was this page helpful?
0 / 5 - 0 ratings