Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit __esModule for every ES6 module emitted. #13709

Closed
mhegazy opened this issue Jan 27, 2017 · 10 comments
Closed

Emit __esModule for every ES6 module emitted. #13709

mhegazy opened this issue Jan 27, 2017 · 10 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Jan 27, 2017

In anticipation for change by the Node CTC to adopt ES6 modules, transpiled modules should all have the flag set. this gives an unambiguous way to know if this is a trsanspiled module of a plain old CJS module.

@yuit
Copy link
Contributor

yuit commented Feb 7, 2017

Export __esModule for all module except when there is export =
Update: such export should be before calling of require to facilitate circular dependency

@pjordaan
Copy link

so how can I configure to disable this emit? I get errors that exports is not defined. And I also see a few related tickets to other projects where this happens too.

@yume-chan
Copy link
Contributor

yume-chan commented Feb 28, 2017

@pjordaan I believe it's a bug, as a workaround you can set module: typescript.ModuleKind.ES2015 in compiler options to get rid of __esModule, I don't know why but ES2015 modules are not affected.

Dev Team think it works as intended, see the referecned bug for discussion.

@ghost
Copy link

ghost commented Mar 13, 2017

Can the emit be either:

Object.defineProperty(exports || {}, "__esModule", { value: true });

or

if( typeof exports !== 'undefined' ) Object.defineProperty(exports, "__esModule", { value: true });

?

@RyanCavanaugh
Copy link
Member

@errorx666 why?

@ghost
Copy link

ghost commented Mar 13, 2017

@RyanCavanaugh I'm using SystemJS with commonjs modules. For a file that has neither imports nor exports, System.import( 'foo' ); does not recognize the file as a module, and so does not define exports (or module, etc). So, the browser throws an error that exports is undefined when we try to define a property on it.

Currently working around this with

export = void 0;

at the bottom of each file.

@pjordaan
Copy link

Same here, but I'm using rollup as a bundler. Not all setups result in a variable exports and this just breaks development for me. If I understand correctly this is only there as hack for running Typescript in node.js.

And shouldn't it be
if (typeof exports !== 'undefined') in case you are in strict mode.

@farfromrefug
Copy link

any news on this? I also get the error that exports is not defined in my react app (electron).
I am stuck with 2.1.4 until this is resolved.

@brian428
Copy link

brian428 commented Apr 6, 2017

There seems to be a lot of debate on this in various issue threads, but the bottom line is that this change is totally wrecking the ability for a lot of people to upgrade to 2.2.x. If a file has no exports, why is this still being emitted? And if the TS team won't suppress this for files without exports, then at least make the ridiculously simply change to have it emit Object.defineProperty(exports || {}, "__esModule", { value: true }); so that it doesn't completely break people's code.

@scf37
Copy link

scf37 commented Aug 30, 2017

I'm using typescript together with Google Closure Compiler and __esModule has no value there.

@scf37 scf37 unassigned yuit Aug 30, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

8 participants