Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'request' of undefined #223

Open
koraniar opened this issue Oct 8, 2018 · 2 comments
Open

Cannot read property 'request' of undefined #223

koraniar opened this issue Oct 8, 2018 · 2 comments
Assignees

Comments

@koraniar
Copy link

koraniar commented Oct 8, 2018

  1. "mailgun-js": "^0.21.0"

  2. Node js v10.5.0 on Windows 10 1803

  3. I don't have tested on other languages

Declaration

const Mailgun = require('mailgun-js');

const service = Mailgun({
    apiKey: MAILGUN_API_KEY,
    domain: MAILGUN_DOMAIN
  });

Implementation

var data = {
      from: 'Excited User <[email protected]>',
      to: '[email protected]', // a real and authorized email is here on my test
      subject: 'Hello',
      text: 'Testing some Mailgun awesomeness!'
    };
service.messages().send(data, function (error, body) {
      // don't enter here
    });

when I call service.messages().send i get this error

error:  message=Cannot read property 'request' of undefined, stack=TypeError: Cannot read property 'request' of undefined
    at constructor.impl (C:\Tulpep\Vtul\vtul-api\node_modules\mailgun-js\lib\build.js:101:26)
    at promisifyCall (C:\Tulpep\Vtul\vtul-api\node_modules\promisify-call\index.js:25:15)
    at constructor.promisifed [as send] (C:\Tulpep\Vtul\vtul-api\node_modules\mailgun-js\lib\build.js:105:14)
    at sendEmail (C:\Tulpep\Vtul\vtul-api\src\services\authManagement\notifier.js:17:45)
    at Object.notifier (C:\Tulpep\Vtul\vtul-api\src\services\authManagement\notifier.js:40:18)
    at Object.create (C:\Tulpep\Vtul\vtul-api\src\services\auth-management\auth-management.class.js:27:32)

Do you know how to solve this?

@bojand
Copy link
Collaborator

bojand commented Oct 9, 2018

Hmm I cannot recreate this... although I am not using Windows, and do not have easy access to that platform. Can you provide a smaller completely reproducible script please, or some more context about how this is used, specifically in sendEmail, and with the Object.notifier and Object.create functions.

@bojand bojand self-assigned this Oct 9, 2018
@koraniar
Copy link
Author

koraniar commented Oct 9, 2018

Thank you for your fast response
Sorry I have not explained well my implementation

I am instantiating mailgun.js as a FeathersJs service

// Initializes the `emails` service on path `/emails`
const hooks = require('./emails.hooks');
// const Mailgun = require('mailgun-js');

module.exports = function (app) {

  // Initialize our service with any options it requires
  app.use('/emails', require('mailgun-js')({
    apiKey: "key-5ab94a...............",
    domain: "sandbox01......................................"
  }));

  // Get our initialized service so that we can register hooks
  const service = app.service('emails');

  service.hooks(hooks);
};

and I am using it here

function sendEmail() {
    var data = {
      from: 'Excited User <[email protected]>',
      to: 'esteban.garc............',
      subject: 'Hello',
      text: 'Testing some Mailgun awesomeness!'
    };
    return app.service('emails').messages().send(data, function (error, body) {
      console.log(body);
    });
  }

the app.service('emails') returns the same object as Mailgun({apiKey: KEY, domain: DOMAIN }); or I see the same object

I have tested it in Mac OS X 10.13.6 with Node js v10.5.0 and I get the same error

error:  message=Cannot read property 'request' of undefined, stack=TypeError: Cannot read property 'request' of undefined
    at constructor.impl (/Users/koraniar/GitHub/Vtul/vtul-api/node_modules/mailgun-js/lib/build.js:101:26)
    at promisifyCall (/Users/koraniar/GitHub/Vtul/vtul-api/node_modules/promisify-call/index.js:25:15)
    at constructor.promisifed [as send] (/Users/koraniar/GitHub/Vtul/vtul-api/node_modules/mailgun-js/lib/build.js:105:14)
    at sendEmail (/Users/koraniar/GitHub/Vtul/vtul-api/src/services/authManagement/notifier.js:19:45)
    at Object.notifier (/Users/koraniar/GitHub/Vtul/vtul-api/src/services/authManagement/notifier.js:42:18)
    at Object.create (/Users/koraniar/GitHub/Vtul/vtul-api/src/services/auth-management/auth-management.class.js:27:32)

but when I initialize mailgun js like the documentation it works well, do you know what it can be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants