grunt-closure-compiler模块抛出IllegalArgumentException

时间:2016-01-26 11:08:08

标签: javascript google-closure-compiler

我使用grunt-closure-compiler任务的this fork来使用闭包编译器构建多个文件。

我设置了以下编译器标志:

--module_output_path_prefix .\  --js lib\test\mod-c.js  --module test_mod__c:1  --js lib\test\mod-d.js  --module test_mod__d:1  --js lib\test\mod-b.js  --module test_mod__b:1:test_mod__c,test_mod__d  --js lib\test\mod-a.js  --module test_mod__a:1:test_mod__b,test_mod__d  --compilation_level "ADVANCED_OPTIMIZATIONS" --language_in "ECMASCRIPT5_STRICT"

每当我运行它时,我都会收到以下错误:

java.lang.IllegalArgumentException: expected one element but was: <test_mod__c, test_mod__d>
at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:317)
at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:289)
at com.google.javascript.jscomp.JSModuleGraph.getRootModule(JSModuleGraph.java:150)
at com.google.javascript.jscomp.AnalyzePrototypeProperties.<init>(AnalyzePrototypeProperties.java:122)
at com.google.javascript.jscomp.CrossModuleMethodMotion.<init>(CrossModuleMethodMotion.java:79)
at com.google.javascript.jscomp.DefaultPassConfig$97.create(DefaultPassConfig.java:2170)
at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:285)
at com.google.javascript.jscomp.PhaseOptimizer$Loop.process(PhaseOptimizer.java:458)
at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:217)
at com.google.javascript.jscomp.Compiler.optimize(Compiler.java:1901)
at com.google.javascript.jscomp.Compiler.compileInternal(Compiler.java:681)
at com.google.javascript.jscomp.Compiler.access$000(Compiler.java:89)
at com.google.javascript.jscomp.Compiler$2.call(Compiler.java:632)
at com.google.javascript.jscomp.Compiler$2.call(Compiler.java:629)
at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:93)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

根据我可以找到的一些来源,这通常是由无效的依赖树引起的,但我不明白为什么它会出错。

1 个答案:

答案 0 :(得分:1)

输出模块必须描述树。该要求意味着所有其他模块从中下降的单个基本模块。基础模块是一个不依赖于其他模块的模块。

你的标志列出了2个基本模块:

  • --module test_mod__c:1
  • --module test_mod__d:1

这些是基础模块,因为它们不依赖于其他模块。从您的评论中,我认为您可能正在向后描述树。根据您a作为切入点的评论,我相信您想要的树看起来像这样:

test_mod__a
└─ test_mod__b
|  ├─ test_mod__c
└─ └─ test_mod__d

以下是描述此树的标志:

--module_output_path_prefix .\
--js lib\test\mod-a.js --module test_mod__a:1
--js lib\test\mod-b.js --module test_mod__b:1:test_mod__a
--js lib\test\mod-c.js --module test_mod__c:1:test_mod__b
--js lib\test\mod-d.js --module test_mod__d:1:test_mod__a,test_mod__b

此外,您可能想要使用official npm version of the compiler - 它现在包含一个grunt插件并支持--module标记。

免责声明:我将Closure编译器的出版物管理到npm并且是插件作者