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

Module 'moment' has no exported member 'MomentFormatSpecification' #343

Closed
stefan505 opened this issue May 23, 2016 · 16 comments
Closed

Module 'moment' has no exported member 'MomentFormatSpecification' #343

stefan505 opened this issue May 23, 2016 · 16 comments

Comments

@stefan505
Copy link

stefan505 commented May 23, 2016

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?

@DaanDeMeyer
Copy link

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

@mattjohnsonpint
Copy link
Contributor

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

@maxkarpovets
Copy link

What is pull request number?

I need it for typings.

@konrad-garus
Copy link

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

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

@berkeleydiego
Copy link

berkeleydiego commented Jul 20, 2016

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

@konrad-garus
Copy link

@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).

@AndreiShostik
Copy link

AndreiShostik commented Jul 24, 2016

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.

@brunolm
Copy link

brunolm commented Aug 5, 2016

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.

@ceolinwill
Copy link

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

@AndreiShostik
Copy link

@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

@ceolinwill
Copy link

ceolinwill commented Aug 16, 2016

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

@titimoby
Copy link

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

@ceolinwill
Copy link

ceolinwill commented Sep 14, 2016

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

@titimoby
Copy link

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

thanks @wceolin

@Wernerson
Copy link

Wernerson commented Aug 8, 2017

@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 moment/moment@0866ff9

This issue should be closed.

@maggiepint
Copy link
Member

Closing since several people are saying fixed.

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