3

We have circular depenency structure that should be fine logically. Light imports Node which imports NodeManager which inturn imports Light. When running our code we get the following

"Super expression must either be null or a function"

NodeManager

// in NodeManager.js
import Light from '../../Light.js'

class NodeManager {
  static _instance;
  static getInstance() {
    if(NodeManager._instance === undefined) {
      NodeManager._instance = new NodeManager();
    }
   return NodeManager._instance;
  }
  ...
  addNode(node){
    ...
    if(node instanceOf Light){
      ...
    }
    ...
  }
}

Node

// in Node.js
import NodeManager from '../../NodeManager.js'
class Node {
  constructor() {
    ...
    NodeManager.instance().addNode(this);
    ...
  }
}

Light

// in Light.js
import Node from '../../Node.js'
class Light extends Node {
  constructor() {
    super();        
    ...
  }
}

For some reason the import of Node in light does not work thus Light.js throws the error when calling super. I am uncertain of how to solve this. Any help is appreciated.

Pablo Jomer
  • 9,870
  • 11
  • 54
  • 102

1 Answers1

0

super() must be the first thing you call in the constructor (see here). It seems like you're missing super() call in the constructor of the Node class.

matmiz
  • 70
  • 9