1
votes

I wrote a JavaScrip application a few years back using the closure framework and compiler. It uses goog.require, goog.provides and goog.inherits a lot, and was working fine using the old python script to build it.

I wanted it working again so I updated the library and compiler and used my old make script. But get this.

Closure Compiler now natively understands and orders Closure dependencies and is prefererred over using this script for performing JavaScript compilation. Please migrate your codebase. See: https://github.com/google/closure-compiler/wiki/Managing-Dependencies

I read the link provided and did not see anything wrong. So I replaced the script with this.

java -jar C:/closure/closure-compiler-v20160713.jar --output_manifest _manifest.txt  
--compilation_level ADVANCED_OPTIMIZATIONS --js M*.js 
--js_output_file _M_min.js

It compiles fine, however when running I get errors such as...

_M_min.js?v=4:23 Uncaught ReferenceError: goog is not defined

_M_min.js?v=4:54 Uncaught TypeError: Cannot read property 'extend' of undefined

I thought the compiler unrolled all of this and did not require including the goog library at run time?

If I do include the library with "js/goog/base.js" I get goog.yb is not a function and so on. But I really did not think I needed to do this.

What am I doing wrong.

1

1 Answers

1
votes

I think there are multiple problems:

  1. You have to include closure library in your compilation as source. Adding --js path/to/closure/**.js will do it.
  2. You need to use the dependency management flags. If you use goog.require and goog.provide in ALL of your files, you'll want strict mode.