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