breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
2.96k stars 80 forks source link

TypeError: Bree is not a constructor #240

Closed Banjer71 closed 6 months ago

Banjer71 commented 6 months ago

Describe the bug

Node.js version: Node v18.7.0

OS version: Windows 10

Description: I am getting this error TypeError: Bree is not a constructor. The script is below , I searched online but I did not get any useful solutions

Code to reproduce

` const { Bree } = require("bree"); const bree = new Bree({ jobs: [ { name: 'sendVerseEmails', interval: '1 minute', worker: async () => { // get songs with verses const songs = await SplittedLyrics.find({ verses: { $exists: true } });

    songs.forEach(async (song) => {
      const verse = getNextVerse(song);

      if (verse) {
        // send verse
        sendVerseByEmail(song.userEmail, verse, song.title);

        // update lastSent
        await SplittedLyrics.findByIdAndUpdate(song._id, {
          lastSent: verse,
        });
      } else {
        // no more verses, delete song
        await SplittedLyrics.findByIdAndDelete(song._id);
      }
    });
  },
},

], }); `

Checklist

titanism commented 6 months ago

You need to use const Bree = require('bree') as noted in our README. Please read the README before filing GitHub issues and spamming users.

Banjer71 commented 6 months ago

@titanism

const Bree = require('bree') I did it already and I was getting another error node:internal/process/promises:289 triggerUncaughtException(err, true / fromPromise /); ^

[Error: ENOENT: no such file or directory, stat 'C:\Users\Davide\Desktop\Lyrics Bites\mern\Lyrics-bites-backend-v2\jobs'] { errno: -4058, code: 'ENOENT', syscall: 'stat', path: 'C:\Users\Davide\Desktop\Lyrics Bites\mern\Lyrics-bites-backend-v2\jobs' }

titanism commented 6 months ago

Again, you need to read the README. It's looking for a folder called jobs which you have to create. See the README (CMD+F/CTRL+F for "jobs").