【问题标题】:Google Closure Library can't get dependencies loading correctly in simple exampleGoogle Closure Library 在简单示例中无法正确加载依赖项
【发布时间】:2016-02-07 16:05:07
【问题描述】:

我正在尝试使用 Closure 模板让 Google Closure 库正常工作,但是当我运行我的应用程序时,它会引发错误 soyutils_usegoog.js:74 Uncaught TypeError: Cannot read property 'StringBuffer' of undefined

我已经研究了所有内容,添加了 goog deps.js 文件,移动了一些东西,但我仍然无法让它运行。 所以我然后从CLosure网站复制了确切的例子来尝试找出它,它仍然给我同样的错误。 我在这里尝试了第一个简单的例子:https://developers.google.com/closure/templates/docs/helloworld_js

如果我在控制台中查询goog.string.StringBuffer,它会返回一个函数,它似乎是最后加载该文件。

【问题讨论】:

    标签: google-closure google-closure-library google-closure-templates


    【解决方案1】:

    您的依赖项必须在您的脚本执行之前加载。通常,在使用调试加载器时,这是通过将入口点的 goog.require 作为脚本标记内容来完成的。 base.js 的加载器将使用 deps.js 中的信息,并在初始化脚本标记之后添加适当的依赖项作为脚本标记。

    如果您使用脚本标签直接加载模板,goog.reqire 的依赖项将在需要它的脚本之后加载,这听起来像是发生在您身上的事情(缺少细节,所以不清楚)

    对于生产用途,您通常会使用 Closure Compiler 或其他感知工具构建一个包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-20
      • 2016-09-22
      • 1970-01-01
      • 2011-10-18
      • 2018-10-06
      • 2012-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多