question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support using goog.require to import an ES6 module

See original GitHub issue

It 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:open
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ChadKillingsworthcommented, Sep 7, 2017

I really need to go document this. It works with this form:

import * as Event from 'goog:goog.event';
1reaction
ricticcommented, Sep 7, 2017

@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 or goog.module?

In the terms of the gist, how would goog-user.js or global-user.js depend on es6-lib.js?

Read more comments on GitHub >

github_iconTop Results From Across the Web

goog.require an ES6 module - Google Groups
Essentially I have a set of existing ES6 modules with imports/exports, and I want to use goog.require to pull them in. It would...
Read more >
Migrating from goog.modules to ES modules - OpenSphere
To import the modules from a legacy file using goog.provide or from tests, use a combination of goog.require to add the dependency and...
Read more >
Google Closure - Import Legacy Class in ES6 Module Class
goog.module('farm.animal.Cow'); // Legacy class using es5 var Animal = goog.require('namespace.Animal'); class Cow extends Animal ...
Read more >
目录 - Gitee
ES6 -modules-and-Closure-Library. The Debug Loader and ES modules goog.require'ing ES modules. Formatting-.js-with-clang-format. Formatting .js with clang- ...
Read more >
Google JavaScript Style Guide
ES module files must use the import statement to import other ES module files. Do not goog.require another ES module. import './sideeffects.js'; import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found