1

If I compile TypeScript for Node.js with

tsc --module commonjs --target ES5

I can't use async/await or generators because tsc doesn't know how to compile it to ES5.

That can be fixed if I compile TypeScript for Node.js with

tsc --module commonjs --target ES6

but then I can't use default parameters or destructuring assignment, because Node.js doesn't support them. tsc knows how to compile those to ES5, but it only does it if you actually target ES5.

How can I target Node.js with support for all of TypeScript's features?

3
  • 1
    You could target ES6 and then use babeljs to compile that for ES5. Commented Feb 15, 2016 at 2:09
  • Yeah, that would work, but it complicates things. I was hoping tsc was the only build tool I needed. I mean, internally it does everything it needs to target Node.js's combination of features, but there doesn't seem to be an option for it. :( Commented Feb 15, 2016 at 2:15
  • Not an answer, but I would also encourage looking at fleshing out your pipeline. Setting up a gulpfile took me all of 20 minutes and does what I need (tsc-> browserify -> header). I thought it would be annoying, turns out it was fine. Commented Feb 15, 2016 at 6:52

1 Answer 1

1

You should be fine with running your ES6 compiled code in latest node.js (v5.x). To enable the particular ES6 featuresthat are not enabled by default you should use --harmony flags. Like this for example:

node --harmony-destructuring

For the complete list of possible harmony features to play with - run:

node --v8-options | grep harmony

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

Comments

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.