Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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 ?).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!