MateMalice / mail-listener2

Mail listener library for node.js. Get notification when new email arrived.
Other
9 stars 7 forks source link

mail-listener5 MailListener is not a constructor #2

Closed rgeber closed 4 years ago

rgeber commented 5 years ago

When running the example code in node 10.15.3 (also newer versions) I get the following error:

const mailListener = new MailListener({
                     ^

TypeError: MailListener is not a constructor

I assume that the example may no longer be up to date, but wasn't able to sort it out yet.

sachya commented 5 years ago

Just go to index.js file of mail-listener5 in node modules and remove MailListener property on module.exports It should be module.exports = MailListener;

MateMalice commented 4 years ago

I agree that @sachya 's solution is the cleanest one. I apologise - the README does not accurately reflect how to import the module, something I will shortly fix.

Although it's been a while since I worked on this module, I believe that I used the module.exports.MailListener = MailListener; syntax because a previous version either had multiple exports or I was considering including multiple exports.

Whilst I am tempted to change index.js in this repo as suggested, I am reluctant to do so as it could break the code of people who have otherwise successfully imported the module.

To require the module, use one of the following methods:

var MailListener = require('mail-listener5').MailListener;    // If you look at test.js in the root directory of the repo, you'll see that this is how the module is imported there

OR

var { MailListener } = require('mail-listener5');    // This won't work with versions of JS before ES6 that do not support destructuring

Closing this as I suspect this will solve your issue. If not, feel free to open another. :-)