question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
alexeaglecommented, Apr 12, 2017

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 .

1reaction
alexeaglecommented, Apr 12, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - ECMAScript Modules in Node.js - TypeScript
When a file is considered an ES module, a few different rules come into play compared to CommonJS: import / export statements and...
Read more >
ES6 Modules · Issue #2242 · microsoft/TypeScript - GitHub
A top-level declaration that specifies an export modifier. An new ES6 export or import declaration of any form. An original TypeScript ...
Read more >
Getting Unexpected Token Export - javascript - Stack Overflow
there is not enough information about your environment or configuration to offer any assistance. This error is suggesting that either webpack or babel...
Read more >
Avoid these issues when using new ECMAScript modules in ...
Es6 modules now have full support in Node.js 12 and above so it's ... to compile in tsc because it is at the...
Read more >
CommonJS modules | Node.js v19.2.0 Documentation
Assigning to exports will not modify module, must use module.exports module.exports ... to build native packages from Node.js modules without modification.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found