Robin Elvin
Robin Elvin

Reputation: 1255

Require external module in Typescript internal module

As the title suggests I have an internal module in which I require an external module (in this case momentjs) If I just have the module definition and reference this in my other files it compiles fine but of course at runtime I get a 'moment is not defined' error. If I then add:

import moment = require('moment');

then the module gets wrapped in the appropriate require([.....]) code but now my other files won't compile due to the module reference not being found.

What is the best way to fix this?

Upvotes: 0

Views: 202

Answers (1)

jkuhel
jkuhel

Reputation: 26

To fix this issue, make sure you have the moment TypeScript definition file included in your project and referenced.

TypeScript definitions

You can include moment as follows:

var moment: moment.MomentStatic = require('moment');

Upvotes: 1

Related Questions