Roberto Gimenez
Roberto Gimenez

Reputation: 304

Typerror is not a constructor

I´ve this error on my code

Typerror: ProjectRepository is not a constructor at main.....

This is the code from main.js

const Promise = require('bluebird')
const AppDAO = require('./dao')
const ProjectRepository = require('./project_repository')
const TaskRepository = require('./task_repository')

function main() {

const dao = new AppDAO('./database.sqlite3')
const blogProjectData = {name: 'Write Node.js - SQLite Tutorial'}
const projectRepo = new ProjectRepository(dao)
const taskRepo = new TaskRepository(dao)
let projectId

This is project_repository.js class with the constructor

class ProjectRepository{
    constructor(dao){
        this.dao = dao
    }

It's very simple but I´ve no idea why it´s failing.

Upvotes: 0

Views: 776

Answers (1)

Aritra Chakraborty
Aritra Chakraborty

Reputation: 12542

Because you are not exporting the ProjectRepository class.

add export before class keyword.

export class ProjectRepository{ ... }

Maybe it's just a silly mistake, but if you want to learn more about Javascript import and exports you can at this link

Upvotes: 4

Related Questions