2

我正在嘗試使用Michael Bolin在Closure: The Definitive Guide中使用簡單的「Hello World」示例plovr開始。但是我的構建產生了一個錯誤。有沒有人能告訴我我的錯誤?爲什麼在「Hello World」plovr示例中的JSC_MISSING_PROVIDE_ERROR?

這裏是我的文件格式:

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": "." 
} 

這裏ar Ë我生成的結果(我在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) 

回答

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實用程序(包括安裝閉合棉絨時)可以修復某些錯誤,但不是全部。一個人可能需要做一些手工編輯。這裏是hello.js兼容皮棉版本:

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);