EternallyCurious
EternallyCurious

Reputation: 2415

Unable to import in typescript file in nodejs

I am trying to import the underscore module in a Typescript file, but its creating trouble because when I run the typescript module in node, it throws an error:

Code:    
import _ = require('underscore');

Error:
import _ = require('underscore');
^^^^^^
SyntaxError: Unexpected reserved word
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)

Upvotes: 1

Views: 1453

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221342

You have to compile the TypeScript file. Then, run the generated .js file in node.

Upvotes: 4

Related Questions