封闭 - 编译器.jar的Google Blockly`命名空间永远不会提供。错误

时间:2018-03-20 13:28:19

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

我问issue,但我仍然无法解决问题。我得到的错误如required "Blockly" namespace never provided

我按照Google bLockly Advanced Compilation教程尝试。我没有在Blockly根目录中创建一个新目录来测试,而是在项目中使用blocklyclosure-library作为子目录(子模块),如下所示:

project
├─blockly
├─closure-library
├─closure-compiler.jar
├─index.html
└─main.js

然后使用如下命令编译文件:

java -jar closure-compiler.jar --js='main.js' ^
  --js='./blockly/**.js' ^
  --js='!./blockly/externs/**.js' ^
  --js='!./blockly/msg/messages.js' ^
  --js='./closure-library/closure/goog/**.js' ^
  --js='./closure-library/third_party/closure/goog/**.js' ^
  --generate_exports ^
  --externs ./blockly/externs/svg-externs.js ^
  --compilation_level ADVANCED_OPTIMIZATIONS ^
  --dependency_mode=STRICT --entry_point=Main ^
  --js_output_file main_compressed.js

堆栈跟踪

main.js:3: ERROR - required "Blockly.Msg.en" namespace never provided
goog.require('Blockly.Msg.en');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

main.js:5: ERROR - required "Blockly" namespace never provided
goog.require('Blockly');
^^^^^^^^^^^^^^^^^^^^^^^

main.js:7: ERROR - required "Blockly.Constants.Logic" namespace never provided
goog.require('Blockly.Constants.Logic');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

main.js:8: ERROR - required "Blockly.Constants.Loops" namespace never provided
goog.require('Blockly.Constants.Loops');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

main.js:9: ERROR - required "Blockly.Constants.Math" namespace never provided
goog.require('Blockly.Constants.Math');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

main.js:10: ERROR - required "Blockly.Constants.Text" namespace never provided
goog.require('Blockly.Constants.Text');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

6 error(s), 0 warning(s)

操作系统

OS: Windows 7
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Closure Compiler Version: v20180204

P.S。即使我遵循教程中的所有步骤(与教程相同的目录结构),我也会遇到相同的错误

1 个答案:

答案 0 :(得分:0)

通常,“未提供名称空间”错误是由于未将提供该名称空间的文件传递给编译器而引起的。您的目录布局非常好,但是对于实际的命令,我发现最好指定特定的文件而不是使用!操作员。我看到很多人对此有疑问。我会尝试以下方法:

`java -jar closure-compiler.jar --js='main.js' \
  --js='blockly/blocks/**.js' \
  --js='blockly/core/**.js' \
  --js='blockly/generators/**.js' \
  --js='blockly/msg/js/**.js' \
  --js='closure-library/closure/goog/**.js' \
  --js='closure-library/third_party/closure/goog/**.js' \
  --generate_exports \
  --externs blockly/externs/svg-externs.js \
  --compilation_level ADVANCED_OPTIMIZATIONS \
  --dependency_mode=STRICT --entry_point=Main \
  --output_manifest manifest.MF
  --js_output_file main_compressed.js`

请注意,这将使您可以通过在manifest.MF中列出来查看实际正在编译的文件。