【问题标题】:Why a JSC_MISSING_PROVIDE_ERROR in "Hello World" plovr example?为什么在“Hello World”plovr 示例中出现 JSC_MISSING_PROVIDE_ERROR?
【发布时间】:2011-04-10 21:10:30
【问题描述】:

我正在尝试使用 Michael Bolin 在Closure: The Definitive Guide 中的简单“Hello World”示例开始使用plovr。但是我的构建会产生错误。有人可以告诉我我的错误吗?

这是我的文件布局:

C:\hello-plovr
├──hello-config.js
├──hello.js
└──plovr-0744c5209a34.jar

这是hello.js的内容:

goog.provide( 'example' );
goog.require( 'goog.dom' );  // line 2

example.sayHello = function( message ) {
    goog.dom.getElement( 'hello' ).innerHTML = message;
}

goog.exportSymbol( 'example.sayHello', example.sayHello );

这是hello-config.js的内容:

{
    "id": "hello-plovr",
    "inputs": "hello.js",
    "paths": "."
}

这是我的构建结果(我把 Java 版本放入以防万一):

C:\hello-plovr> java -jar plovr-0744c5209a34.jar build hello-config.js
JSC_MISSING_PROVIDE_ERROR. required "goog.dom" namespace never provided at hello.js line 2 : 12
BUILD FAILED: 1 Errors, 0 Warnings

我一定遗漏了一些微不足道的东西,但我没有看到它。

如果重要的话,这是使用 Java 1.6.0_24 运行的:

C:\hello-plovr> java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

【问题讨论】:

    标签: google-closure-compiler google-closure google-closure-library plovr


    【解决方案1】:

    如上所述,这最初是由于 plovr 中的一个错误:

    http://code.google.com/p/plovr/issues/detail?id=37

    但是,plovr 中的这个错误已得到修复,并在 2011 年 4 月发布的 plovr 中可用。

    【讨论】:

      【解决方案2】:

      使用更新版本的 plovr(2011 年 4 月或更高版本)或不要在 goog.require 中使用空格。更改hello.js,第2行如下:

      goog.require('goog.dom');  // NO SPACES
      

      在此处报告为 plovr 错误:http://code.google.com/p/plovr/issues/detail?id=37

      Plovr 作者建议使用closure-linter,因为它会警告空格问题:

      PS C:\hello-plovr> gjslint --strict hello.js
      ----- FILE  :  C:\hello-plovr\hello.js -----
      Line 4, E:0007: (New error) Should have 2 blank lines between top-level blocks.
      Line 5, E:0214: Missing description in @param tag
      Line 7, E:0001: Extra space after "("
      Line 7, E:0001: Extra space before ")"
      Line 8, E:0005: Illegal tab in whitespace before "goog.dom.getElement"
      Line 8, E:0001: Extra space after "("
      Line 8, E:0001: Extra space before ")"
      Line 9, E:0011: Missing semicolon after function assigned to a variable
      Line 11, E:0001: Extra space after "("
      Line 11, E:0001: Extra space before ")"
      Found 10 errors, including 1 new errors, in 1 files (0 files OK).
      
      Some of the errors reported by GJsLint may be auto-fixable using the script
      fixjsstyle. Please double check any changes it makes and report any bugs. The
      script can be run by executing:
      
      fixjsstyle --strict hello.js
      

      如前所述,fixjsstyle 实用程序(在安装closure-linter 时包含)可以修复一些错误,但不是全部。可能需要进行一些手工编辑。这是 hello.js 的 lint 兼容版本:

      goog.provide('example');
      goog.require('goog.dom');
      
      
      /**
       * @param {string} message A greeting message.
       */
      example.sayHello = function(message) {
        goog.dom.getElement('hello').innerHTML = message;
      };
      
      goog.exportSymbol('example.sayHello', example.sayHello);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-12
        相关资源
        最近更新 更多