3

Got a situation here. I use nodejs with --harmony flag to get support of generators. Next i'm trying to switch my project to TypeScript and get a problem: in "target":"ES6" mode it transpiles import commands as is (instead of require).

And node with --harmony flag doesn't support that:

import * as fs from 'fs';
^^^^^^
SyntaxError: Unexpected reserved word

Transpiling option "module":"commonjs isn't allowed with "target":"ES6".

Have anyone solved this problem without using any external require/import utilities?

1
  • Another side of the problem is that TypeScript transpiles var fs = require('fs'); into import * as fs from 'fs'; on it's own. So, no way to avoid import commands. Commented Oct 13, 2015 at 12:09

3 Answers 3

3

These settings have worked for me:

tsconfig.json

{
  "compilerOptions": {
    "target":"ES6",
    "moduleResolution": "classic",
  }
}
  • ES6 support for generators
  • No import stuff transpiling due to "moduleResolution": "classic"

And so the problem's gone!

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

2 Comments

We still couldn't achieve this using solely ts, I guess we need separate transpiler like babel to convert final es6 file to es5
OP: "...without setting target to ES6?" also OP: "target":"ES6"
1

As you can see in the TypeScript roadmap (Version 1.7) one of the current issues is "Support --module with --target es6".

I'm afraid your are going to need a temporal solution until TypeScript 1.7 is released. Maybe Polyfill for the ES6 Module Loader or SystemJS?

Comments

0

Another way to get all i want is a build stack:

  1. Transpile TS to ES6
  2. Transpile es6-js to es5-js with Babel

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.