Cannot access 'Agent' before initialization [duplicate]

Solution 1:

Classes, like variables declared with const and let, cannot be referenced before the line that initializes them runs. For example, the following is forbidden:

console.log(foo);
const foo = 'foo';

classes have the same rule. Here, you're calling init before the class Color line has run. The fix is to do:

const foo = 'foo';
console.log(foo);

or, in this case:

class Color {
  // ...
}
init(); // only call init once Color has been defined

Move the Color class up to the top, or move the init() call to the bottom of the script, or otherwise somehow make sure Color is defined by the time you call init.