2

In Typescript 1.7 a feature was added that allows to separately target language system and module system, ex it can produce ES6 code with CommonJS module system for latest node. But if I try it with following command and source code:

tsc *.ts --target es6 --module commonjs

 

// foo.ts
"use strict";
import Bar from './bar';
console.log(Bar);

 

// bar.ts
"use strict";
export default class Bar {}

Surprisingly, resulting code have some very strange export notation being generated:

// foo.js
"use strict";
var bar_1 = require('./bar');
console.log(bar_1.default);

 

// bar.js
"use strict";
class Bar {}
exports.Bar = Bar;

As you can see, bar.js results in being exporting Bar object, while foo.js attempts to import default object. And of course this code displays "undefined" being imported if executed via latest nodejs v4.1.0

Any hints why such strange behaviour?

1 Answer 1

2

You found a bug in TS 1.7. I believe this is the correct issue:

I verified it by running the code in TS@next (Version 1.8.0-dev.20151216):

npm install typescript@next --save
node node_modules/typescript/bin/tsc --target es6 --module commonjs *.ts && node foo.js
Sign up to request clarification or add additional context in comments.

1 Comment

Ineed it is! Thanks a lot, I was sure that this functionality being on official "what's new" list is a safeguard that they tested it at last once and it works, so I was sure it is my fault and I don't know something about modern module resolution techniques.

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.