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.

Can't compile async function with library injection disabled

See original GitHub issue

Sample input code:

(async function(){})()

Expected output: it compiles Actual output:

liam$ java -jar /usr/lib/node_modules/google-closure-compiler/compiler.jar --inject_libraries=false <<< '(async function(){})()'
The compiler is waiting for input via stdin.
java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.

Unexpected variable $jscomp
  Node(NAME $jscomp): stdin:1:17
(async function(){})()
  Parent(GETPROP): stdin:1:17
(async function(){})()

	at com.google.javascript.jscomp.VarCheck.visit(VarCheck.java:207)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:730)
	at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
	at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
	at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
	at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
	at com.google.javascript.jscomp.NodeTraversal.traverseBlockScope(NodeTraversal.java:817)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:724)
	at com.google.javascript.jscomp.NodeTraversal.traverseFunction(NodeTraversal.java:761)
	at com.google.javascript.jscomp.NodeTraversal.handleFunction(NodeTraversal.java:692)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:708)
	at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
	at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
	at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
	at com.google.javascript.jscomp.NodeTraversal.handleScript(NodeTraversal.java:680)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:705)
	at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:802)
	at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:726)
	at com.google.javascript.jscomp.NodeTraversal.traverseRoots(NodeTraversal.java:325)
	at com.google.javascript.jscomp.VarCheck.process(VarCheck.java:145)
	at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:307)
	at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:233)
	at com.google.javascript.jscomp.Compiler.performOptimizations(Compiler.java:2459)
	at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:844)
	at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:840)
	at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:93)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Unexpected variable $jscomp
	... 35 more

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shickscommented, Jul 19, 2017

Presumably we could handle this by adding an extern /** @type {?} */ var $jscomp; instead of injecting anything if --inject_libraries=false.

If we added the option to the online debugger then we could have the added benefit of not outputting lots of extra junk when we’re not interested in that part of the compile.

0reactions
leidegrecommented, Aug 4, 2021

Presumably we could handle this by adding an extern /** @type {?} */ var $jscomp; instead of injecting anything if --inject_libraries=false.

I tried appending that to scripts that I compile with --inject_libraries=false and it worked!

I also tried this as a workaround and it did also work.

"[{\"src\":\"/** @externs */\\n\\n/** @type {?} */ var $jscomp\",\"path\":\"externs/jscomp.js\"},{\"src\":\"async function foo(){};foo()\",\"path\":\"foo.js\"}]"

I use the closure compiler to minify individual JavaScript files because I need to do the code splitting dynamically at run time.

I just want to leverage the compiler to minify (and transplie) individual JavaScript files to different targets. Please don’t forget about this use case. Even if the compiler was designed to be used in a certain way for maximum effect, I think it can do a lot of good when used as a component like this but I need this bit of modularity for that to work.

When the vscomp runtime is included in every file it adds so much weight. What I want to do in this case is that I use force inject to include the runtime in my entry point and I then compile everything else with --inject_libraries=false.

I have my workarounds, but I just wanted to say thanks for an awesome tool and please don’t forget that people like me exist that use the compiler without the closure library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Await is a reserved word error inside async function
In order to use await , the function directly enclosing it needs to be async. According to your comment, adding async to the...
Read more >
Removing async void - John Thiriet
When using async await we inevitably have to mark methods as async void. This leads to a lot of issues for programmers…
Read more >
Frequently Asked Questions - Jasmine Documentation
What can I do? Why can't my asynchronous function call `done` more than once? What should I do instead? How do I test...
Read more >
How to Use Async and Await with Vue.js Apps - Medium
The form allows us to add and edit our contacts also we can get and delete contacts. To build our app, first we...
Read more >
VM (executing JavaScript) | Node.js v19.2.0 Documentation
The node:vm module enables compiling and running code within V8 Virtual Machine ... throw new Error(`Unable to resolve dependency: ${specifier}`); } await ......
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