3
votes

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?

3
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. - Ivan Pesochenko

3 Answers

3
votes

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!

1
votes

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?

0
votes

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