mailgun / mailgun-js-boland

A simple Node.js helper module for Mailgun API.
http://bojand.github.io/mailgun-js
MIT License
895 stars 122 forks source link

Invalid parameter type. invoke must be of type: undefined. #173

Open sabbir-hossain opened 7 years ago

sabbir-hossain commented 7 years ago

I have the following error in my project.

 Error: Invalid parameter type. invoke must be of type: undefined.
    at constructor.impl (/home/pc/project/node_modules/mailgun-js/lib/build.js:96:17)
    at promisifyCall (/home/pc/project/node_modules/promisify-call/index.js:25:15)
    at constructor.(anonymous function) [as send] (/home/pc/project/node_modules/mailgun-js/lib/build.js:111:12)
    at EmailService.send (/home/pc/project/dist/webpack:/src/components/email/email.service.ts:66:23)
    at EmailController.send (/home/pc/project/dist/webpack:/src/components/email/email.controller.ts:26:28)
    at EmailRoute.send (/home/pc/project/dist/webpack:/src/components/email/email.routes.ts:23:24)
    at /home/pc/project/dist/webpack:/src/components/auth/authorize.ts:26:26
    at _fulfilled (/home/pc/project/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/home/pc/project/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/home/pc/project/node_modules/q/q.js:796:13)
    at /home/pc/project/node_modules/q/q.js:604:44
    at runSingle (/home/pc/project/node_modules/q/q.js:137:13)
    at flush (/home/pc/project/node_modules/q/q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)

And my answer of the following question:

1) What version of the module is the issue happening on? Does the issue happen on latest version? ans: "mailgun-js": "^0.13.1"

2) What platform and Node.js version? (For example Node.js 6.9.1 on Mac OS X) ans: v6.11.0 on Linux and v6.6.0 on Mac OS X

3) Does the action work when you manually perform request against mailgun using curl (or other means)? ans: I can send mail using demo node.js project. But same code is not working on my project where I'm using typescript

4) Sample source code or steps to reproduce

import {injectable, inject} from "inversify";

@injectable()
export class EmailService  {
   send() {
       const mailgun =  require('mailgun-js')({
            apiKey: "key-api-key",
            domain: "domain-name",
        });

       const data = {
         from: "from-address",
         to: "to-address",
         subject: "email subject",
        html: "email-body"
       }
      // error 
      mailgun.messages().send(data, function (err, body) {
        if (err) {
        console.log("got an error: ", err);
        }
        else {
        console.log(body);
        }
       });
  }
}

My package.json file:

{
  "name": "project",
  "version": "1.0.0",
  "description": "project",
  "scripts": {
    "watch": "webpack --watch",
    "server": "nodemon dist/index.js",
    "start": "npm run server"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "keywords": [
    "Server"
  ],
  "author": "",
  "license": "ISC",
  "homepage": "",
  "dependencies": {
    "@types/moment": "^2.13.0",
    "body-parser": "^1.16.0",
    "colors": "^1.1.2",
    "compression": "^1.6.2",
    "cors": "^2.8.1",
    "express": "4.14.1",
    "express-session": "^1.15.3",
    "helmet": "^3.4.0",
    "inversify": "^3.0.0",
    "inversify-dts": "^3.0.0",
    "jsonwebtoken": "^7.2.1",
    "mailgun-js": "^0.13.1",
    "mustache": "^2.3.0",
    "path": "0.12.7",
    "q": "1.4.1",
    "reflect-metadata": "^0.1.9",
    "request": "^2.81.0"
  },
  "devDependencies": {
    "@types/body-parser": "0.0.33",
    "@types/colors": "^1.1.1",
    "@types/compression": "0.0.33",
    "@types/cors": "^2.8.0",
    "@types/helmet": "0.0.33",
    "@types/inversify": "^2.0.33",
    "@types/q": "0.0.32",
    "@types/reflect-metadata": "0.0.5",
    "copy-webpack-plugin": "4.0.1",
    "http-server": "^0.9.0",
    "json-loader": "^0.5.7",
    "nodemon": "^1.11.0",
    "source-map-support": "^0.4.11",
    "ts-loader": "2.0.0",
    "typedoc": "^0.5.5",
    "typescript": "2.1.5",
    "webpack": "2.1.0-beta.22",
    "webpack-merge": "2.6.1",
    "webpack-node-externals": "1.5.4"
  }
}
bojand commented 7 years ago

This looks like it's Angular? Or at least client-side in browser judging by webpack in path? This module is meant to be used from server side within Node.js environment. Not within browser.

sabbir-hossain commented 7 years ago

I am sorry, but it is not Angular project. Ofcourse I am using mailgun-js for server side with Node.js environment. I am using webpack to compile typescript into js.