简体   繁体   English

在简单的示例中,Google Closure库无法正确加载依赖项

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

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 . 我正在尝试使用具有封闭模板的google封闭库,但是当我运行我的应用程序时,它将引发错误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. 我已经研究了所有内容,添加了goog deps.js文件,四处移动,但仍然无法运行。 So i then copied the exact example from the CLosure Website to try figure it out and it still gives me the same error. 因此,我然后从CLosure网站复制了确切的示例以尝试找出答案,但它仍然给我同样的错误。 I tried the first simple example here: https://developers.google.com/closure/templates/docs/helloworld_js 我在这里尝试了第一个简单的示例: 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. 如果我在控制台中查询goog.string.StringBuffer ,它将返回一个函数,似乎它最后一次加载了该文件。

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. 通常,在使用调试加载程序时,可通过将入口点的goog.require用作脚本标签内容来完成此操作。 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. 来自base.js的加载程序将使用deps.js中的信息,并在初始化脚本标签之后添加适当的依赖项作为脚本标签。

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) 如果您直接使用script标签加载模板,则goog.reqire的依赖项将在需要脚本的脚本之后加载,这听起来像您正在发生的事情(缺少详细信息,所以不清楚)

Typically for production use you would build a bundle using the Closure Compiler or other aware tools. 通常用于生产用途时,您将使用Closure Compiler或其他感知工具来构建软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM