Google Closure Library can't get dependencies loading correctly in simple example

423 Views Asked by At

I'm trying to get google Closure Library with Closure Templates working however when I run my app it throws an error soyutils_usegoog.js:74 Uncaught TypeError: Cannot read property 'StringBuffer' of undefined.

I've research everything, added the goog deps.js file, moved things around however I still can't get it to run. So i then copied the exact example from the CLosure Website to try figure it out and it still gives me the same error. I tried the first simple example here: https://developers.google.com/closure/templates/docs/helloworld_js

If I query goog.string.StringBuffer in the console it returns a function, it just seems that its loading that file last.

1

There are 1 best solutions below

0
On

Your dependencies must be loaded before your script is executed. Typically, when using the debug loader this is done by putting the goog.require for your entry point as script tag contents. The loader from base.js will use the info in deps.js and add the appropriate dependencies as script tags after the initialing script tag.

If you directly load the template using a script tag, the goog.reqire'd dependencies will load after the script that needs it, which sounds like what is happening to you (there are details missing so it is unclear)

Typically for production use you would build a bundle using the Closure Compiler or other aware tools.