Closure-compiler: ERROR - Exports must be a statement at the top-level of a module when compiling es6 output from typescript compiler

Created on 12 Apr 2017  Â·  7Comments  Â·  Source: google/closure-compiler

Typescript output for an enum fails to compile with closure compiler because it assigns an export inside of a statement. For example

export enum Foo {}

transpiles to

var Foo;
(function (Foo) {
})(Foo = exports.Foo || (exports.Foo = {}));

as demonstrated here

When closure compiler is run on that code it results in the error ERROR - Exports must be a statement at the top-level of a module

I don't believe that this should cause an error. Es6 supports this syntax. At the very least a there should be an option to make this into a warning or @suppress it.

Most helpful comment

I don't think that's the right option, should be
"angularCompilerOptions": {
"annotateForClosureCompiler": true
}

On Wed, Apr 12, 2017 at 1:35 PM Tyler Davis notifications@github.com
wrote:

with "googleClosureOutput": true

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/closure-compiler/issues/2429#issuecomment-293699755,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAC5IzZHS8MSiNR-qLCpfch7iiU6AuGnks5rvTWngaJpZM4M75ik
.

All 7 comments

cc @alexeagle

Did you build your TypeScript code with tsickle? https://www.npmjs.com/package/tsickle

@alexeagle this is output from Angular 2's ngc

with "googleClosureOutput": true and angular version 4.0.1

I don't think that's the right option, should be
"angularCompilerOptions": {
"annotateForClosureCompiler": true
}

On Wed, Apr 12, 2017 at 1:35 PM Tyler Davis notifications@github.com
wrote:

with "googleClosureOutput": true

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/closure-compiler/issues/2429#issuecomment-293699755,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAC5IzZHS8MSiNR-qLCpfch7iiU6AuGnks5rvTWngaJpZM4M75ik
.

"googleClosureOutput" is something that we added at lucid last summer. updating it to "annotateForClosureCompiler" fixed it. (amazingly it compiled and worked with only a single runtime error before updating closure where this error appeared)

Oh, hi, you didn't use the magic word. I remember that option now - it was from the early prototype of tsc_wrapped that you guys forked. Glad it's fixed.

Was this page helpful?
0 / 5 - 0 ratings