为什么“Hello World”中出现 JSC_MISSING_PROVIDE_ERROR普洛弗的例子?

发布于 2024-10-31 14:29:59 字数 1351 浏览 1 评论 0原文

我正在尝试使用 plovr 中的简单“Hello World”示例开始使用 plovr /oreilly.com/catalog/0636920001416" rel="nofollow">关闭:权威指南作者:Michael Bolin。但我的构建产生了错误。有人可以告诉我我的错误吗?

这是我的文件布局:

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)

I'm trying to get started with plovr using the simple "Hello World" example in Closure: The Definitive Guide by Michael Bolin. But my build produces an error. Can anyone out there enlighten me as to my mistake?

Here is my file layout:

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

This is the contents of 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 );

And this is the contents of hello-config.js:

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

Here are my build results (I threw in the Java version in case that matters):

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

I must be missing something trivial but I'm not seeing it.

In case it matters, this was run with 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街角迷惘 2024-11-07 14:29:59

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

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

不过,plovr 中的此错误已得到修复,并可从 2011 年 4 月发布的 plovr 开始使用。

As noted above, this was originally due to a bug in plovr:

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

However, this bug in plovr has been fixed and is available as of the April 2011 release of plovr.

夜雨飘雪 2024-11-07 14:29:59

使用较新版本的 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);

Use a newer version of plovr (April 2011 or later) OR don't use spaces in goog.require. Change hello.js, line 2 as follows:

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

Reported as a plovr bug here: http://code.google.com/p/plovr/issues/detail?id=37

Plovr author suggests using closure-linter as it warns about whitespace issues:

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

As indicated, the fixjsstyle utility (included when closure-linter is installed) can fix some errors but not all. One will probably need to do some hand editing. Here is a lint-compliant version of 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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文