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

moment.d.ts is not compatible with 'none' module compiler option #3663

Closed
VolodymyrBaydalka opened this issue Dec 15, 2016 · 7 comments
Closed

Comments

@VolodymyrBaydalka
Copy link

I have web application that doesn't use any kind of modules, tsconfig.json -> compilerOptions { "module": "none" }. I tried to use declaration file from package with it, but always get error TS2304: Cannot find name 'moment'.

Steps to reproduce:

create application folder
add typescript config and set compilerOptions { "module": "none" } in tsconfig.json
add moment package via npm
add main.ts with some "moment" code (example: console.log(moment.version) )
try build with tsc
error TS2304 occurred

copy moment.d.ts to application folder
try build with tsc
error TS2304 occurred

add ///<reference path='./moment.d.ts'/>
try build with tsc
error TS2304 occurred

Environment:
npm: 3.10.9
typescript: 2.1.4
moment: 2.17.1

Notes:
Declaration file from the typings works well, and moment it's the only package why I'm still using typings in my project. I checked what the difference is and difference is how they export moment. Instead of export moment they use declare module "moment" { export moment; }

@strohhut
Copy link

For googlers: Changing export = moment; in the declaration to

declare module "moment" {
    export = moment;
}

works. (OP forgot the equals char)

@maggiepint
Copy link
Member

Given the staleness, I'm going to assume that the comment answered your question. Let me know if it didn't.

@strohhut
Copy link

strohhut commented Feb 9, 2017

@maggiepint I don't think that this issue is a question. I think that moment`s declaration file should be changed so that it can work without any module system.

@VolodymyrBaydalka
Copy link
Author

I'm not looking for answer, because I mentioned the same in Notes section. I would like to see this changes in moment's declaration.

@karan-kang
Copy link

karan-kang commented Mar 21, 2017

This issue is still not fixed in v2.18.0. Why is this bug closed?

@marwahaha
Copy link
Member

I'll re-open this, but the solution needs to be Typescript 1.x compatible and non-breaking.

For Moment.js 3.x (coming soon!) we will support Typescript 2.x and can do some breaking changes.

@marwahaha marwahaha reopened this Mar 22, 2017
@marwahaha
Copy link
Member

Closing this as it is a duplicate of #3763 which has more traffic . We still do need a fix!

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

6 participants