'Failing call to class constructor of different module

I know there similar questions have been asked, but I just can't seem to this worked out.

I have two scripts:

// taskList.js
const task = require('task');

var taskList = {

     ...

     addTask: function (targetId, taskType) {
    
         ...
         let newTask = new task.Task(targetId, taskType);
    

    },

    ...

};

module.exports = taskList;

// task.js
class Task {
  
    constructor(targetId, taskType) {
        this.targetId = targetId;
        this.taskType = taskType;
    }

    ...

}

module.exports = Task;

Tasklist is supposed to become a class, too. But that's beside the point. I get this error:

TypeError: task.Task is not a constructor
    at Object.addTask (taskList:34:23)
    at createTaskList (main:187:18)
    at Object.module.exports.loop (main:136:5)
    at __mainLoop:1:52
    at __mainLoop:2:3
    at Object.exports.evalCode (<runtime>:15845:76)
    at Object.exports.run (<runtime>:46468:24)

I have tried to return the class as an object, to write task with uppercase letter first, "new Task()", "new task()", new Task.Task() and so on...

What am I missing here ?

Edit: Added the part where I try to call the constructor.

CreateTasklist is in another script which imports the taskList object (later to also be a class) and calls its function addTask



Solution 1:[1]

Ok, got it. The solution is to call "new task()" instead of "new task.Task()".

I did try that, but didn't realize that I was getting another error then (from the file which calls createTaskList().

Thank you Barma ! I didn't find a way to mark your answer as accepted (maybe I have to earn that right first ?).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Achim Müller