Google Closure - Import Legacy Class in ES6 Module Class

400 Views Asked by At

I have a code base written using ES5, and I want to update just part of the code to ES6 using Modules. This is the code I have:

goog.module('farm.animal.Cow');

// Legacy class using es5
var Animal = goog.require('namespace.Animal');

class Cow extends Animal {
  constructor() {
    super();
  }
}

exports = Cow;

and this is the legacy class

goog.provide('namespace.Animal');

namespace.Animal = function() {

};

I tried to follow the migration recommendations on the GitHub Wikis of both projects:

https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide

https://github.com/google/closure-compiler/wiki/Migrating-from-goog.modules-to-ES6-modules

but no luck so far. Most of the time I get the following error:

depstree.NamespaceNotFoundError: Namespace "namespace.Animal" never provided.

Does anyone have any idea about how should be the proper way to migrate the code? What am I doing wrong?

0

There are 0 best solutions below