How to import a variable from HTML into Google Closure

32 views
Skip to first unread message

Wayne Fulton

unread,
Aug 31, 2024, 10:47:41 AM8/31/24
to Closure Compiler Discuss
I would like to know how to import a single variable into Google Closure.

Not a library, but a simple Var in a standalone script in a HTML file that also will load the Closure .js file.

I have 2 HTML files loading the same Closure .js file.  Each HTML has this simple variable telling the .js which HTML to handle.

This has worked fine for several years (last OK time running Closure on it was Feb of this year), no problem, but now running Google Closure says JSC_UNDEFINED_VARIABLE: which is that var.

I could skip using Closure, but I love what it does.

I assume I need to somehow import it now, but it is not a module, but just a simple var in a script in the HTML file (that Closure does not see). The .JS code always saw it in the same work space. But I don't know how to make it work in Closure again now.

If someone could tell me how to code that in the .js, or direct me to a page that says how, I would greatly appreciate it.

lha...@google.com

unread,
Aug 31, 2024, 10:50:22 AM8/31/24
to Closure Compiler Discuss
You can create an "externs" .js file that tells Closure Compiler about the var declaration, and pass file that to Closure Compiler. See https://developers.google.com/closure/compiler/docs/externs-and-exports#externs.

/**
  * @fileoverview
  * @externs
  */
var myVar;




Reply all
Reply to author
Forward
0 new messages