mailgun-js-boland
mailgun-js-boland copied to clipboard
Cannot read property 'params' of undefined
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 (
-
What version of the module is the issue happening on? Does the issue happen on latest version? 0.22.0
-
What platform and Node.js version? (For example Node.js 6.9.1 on Mac OS X)
8.10.0
- Does the action work when you manually perform request against mailgun using curl (or other means)?
Yes
- 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)
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.