ERROR - Closure dependency methods(goog.provide, goog.require, etc) must be called at file scope.
What DID work for me is this:
goog.provide('MyMainModule');
goog.require('module$pako$index'); // identify the dependency using the mangled module name
MyMainModule.pako = null; // create a local reference to avoid polluting global namespace
if(!MyMainModule.pako) { // necessary to avoid "ERROR - goog.module.get can not be called in global scope."
MyMain.Module.pako = goog.module.get('module$pako$index');
}
// and now I can use "MyMainModule.pako" the same way as "pako" in the CommonJS example!
This seems awkward for a few reasons:
- needing to use the mangled "module$" name, as mentioned in the Github issue discussion
- the strange if() block to avoid "ERROR - goog.module.get can not be called in global scope.".
- the straightforward attempt to use:
MyMainModule.pako = goog.require('module$pako$index');
causes "ERROR - Closure dependency methods(goog.provide, goog.require, etc) must be called at file scope."
Is there a better "intended" way to do things? The above method actually works, and does seem to carry over type information from annotations in the CommonJS library into my main code, which is very cool! Just wondering about the odd syntax I needed to get it working.
btw this is all with Closure Compiler master as of 20160212. Happy to test again with a newer version if anything's changed.
Many thanks,
Dan Maas
To view this discussion on the web visit https://groups.google.com/d/msgid/closure-compiler-discuss/4f993bc5-b7c6-41cf-92a7-b606133596ba%40googlegroups.com.--
---
You received this message because you are subscribed to a topic in the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/closure-compiler-discuss/6H4oNj2pBf4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to closure-compiler-d...@googlegroups.com.
goog.provide('MyMainModule');
This is unintended and will be removed in the next release. CommonJS module rewriting should not effect goog.module code.
I'll be updating the documentation this next week with examples of module interoperability.
Chad Killingsworth
--
---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/closure-compiler-discuss/d83d17e9-3e0f-45a0-ad4f-96b68b9f01eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chad Killingsworth | Banno | Senior Software Engineer
Jack Henry & Associates, Inc.