mailgun-js-boland icon indicating copy to clipboard operation
mailgun-js-boland copied to clipboard

Cannot read property 'params' of undefined

Open recidive opened this issue 6 years ago • 1 comments

TypeError: Cannot read property 'params' of undefined at impl (/.../node_modules/mailgun-js/lib/build.js:42:16) at callback (/.../node_modules/promisify-call/index.js:32:8) at /.../node_modules/with-callback/index.js:39:7 at new Promise () at withCallback (/.../node_modules/with-callback/index.js:5:10) at promisifyCall (/.../node_modules/promisify-call/index.js:28:10) at promisifed (/.../node_modules/mailgun-js/lib/build.js:105:14) at post (/.../src/handlers.js:39:3) at at process._tickCallback (internal/process/next_tick.js:188:7)

  1. What version of the module is the issue happening on? Does the issue happen on latest version? 0.22.0

  2. What platform and Node.js version? (For example Node.js 6.9.1 on Mac OS X)

8.10.0

  1. Does the action work when you manually perform request against mailgun using curl (or other means)?

Yes

  1. Sample source code or steps to reproduce
const mailgun = require('mailgun-js')

const sendMail = mailgun({
  apiKey: MAILGUN_API_KEY,
  domain: MAILGUN_DOMAIN,
}).messages().send

const payload = {
  from,
  to,
  subject,
  text,
}

await sendMail(payload)

(Write description of your issue here, stack traces from errors and code that reproduces the issue are helpful)

recidive avatar Jan 09 '19 18:01 recidive

Hi @recidive - this is a generic (much despised) javascript "foot-gun". When you assign the send function to a variable, and call it later standalone, it is called unbound from the mailgun instance. For example, const qs = document.querySelector; qs('this.will.error'); If you bind the function though const qs = document.querySelector.bind(document); qs('all.is.well');

You could leave the issue open if your desire is to explore mailgun-js binding it's functions to accommodate this usage; otherwise, binding your send method resolves the issue.

craigmichaelmartin avatar May 10 '19 01:05 craigmichaelmartin