Reputation: 73
test.ts
export class Test {
whatever(): Promise<any> {
return undefined;
}
}
Trying to compile with old version:
$ tsc --version
message TS6029: Version 1.4.1.0
$ tsc --target es6 --module commonjs test.ts
$ cat test.js
var Test = (function () {
function Test() {
}
Test.prototype.whatever = function () {
return undefined;
};
return Test;
})();
exports.Test = Test;
This is fine. Now with new version:
$ ./node_modules/.bin/tsc --version
message TS6029: Version 1.5.0-beta
$ ./node_modules/.bin/tsc --target es6 --module commonjs test.ts
error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher.
Why is that? I am developing NodeJS application, so I have to use commonjs. Also, I need native promises, hence es6 target.
$ ./node_modules/.bin/tsc --target es5 --module commonjs test.ts
test.ts(2,14): error TS2304: Cannot find name 'Promise'.
Upvotes: 4
Views: 2364
Reputation: 251172
If you are compiling to a target that supports ES6, you should use ES6 module imports, rather than commonjs or AMD.
import * as Promise from 'Promise';
Remove the --module
flag when you compile if you supply --target ES6
.
Upvotes: 3