Answer the question
In order to leave comments, you need to log in
What causes the "Xxxx is not a constructor" error when including a class via require in Node.js?
Hello!
I ran into a problem, for some reason the class connected via require is written to a constant as an object:
const LietnerBox = require('../entities/LietnerBox');
const RepeatResult = require("../dto/RepeatResult");
// const LietnerBox = require('../entities/LietnerBox'); //получаю ошибку "LietnerBox is not a constructor"
class CardMover {
...
/**
* @param repeatResult {RepeatResult}
* @return {LietnerBox}
*/
_getNextBox(repeatResult) {
const LietnerBox = require('../entities/LietnerBox'); //код выполняется корректно
return new LietnerBox(1);
}
...
}
module.exports = CardMover;
class LietnerBox {
/**
* @param num {Number}
*/
constructor(num) {
this._num = num;
...
}
...
}
module.exports = LietnerBox;
Answer the question
In order to leave comments, you need to log in
Dear Lynn "Coffeeman" , turned out to be right!
Lynn "Coffee Man" :
Wangyu cyclical addiction
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question