Support using goog.require to import an ES6 module
See original GitHub issueIt would be helpful – and likely even necessary – to be able to use goog.require
to import ES6 modules in order to migrate a large codebase to the ES6 module system.
The wiki mentions interop and demonstrates doing a CommmonJS require
of an ES6 module, but doesn’t mention using goog.require
: https://github.com/google/closure-compiler/wiki/JS-Modules#module-interoperation
In basic experiments, importing a module by its transformed path (e.g. goog.require('module$path$to$module$file')
) compiles correctly. This doesn’t seem like a stable or supported way of importing a module though.
I put together some experiments at https://gist.github.com/rictic/f042c2adf30101597fa5bd34a23d992d (buildable internal link: https://goto.google.com/js-module-interop-experiment) demonstrating different combinations of goog.module
, goog.provide
and ES6 modules as best as I understand the situation today.
Related bug: https://github.com/google/closure-compiler/issues/1877
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
I really need to go document this. It works with this form:
@ChadKillingsworth This issue is for going the other direction. What should a user do, who wants to import an ES6 module from a file that uses
goog.provide
orgoog.module
?In the terms of the gist, how would
goog-user.js
orglobal-user.js
depend ones6-lib.js
?