1

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)

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

I have a file watcher in Webstorm (the IDE I'm using) that does that automatically. Are there any other possibility?
Either WebStorm is failing to correctly compile the file, or you're running node on the .ts instead of the .js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.