简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM