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

undefined is not a function (functions must be bound by 'request'). #1506

Closed
noseglid opened this issue Mar 25, 2015 · 7 comments · Fixed by #1515
Closed

undefined is not a function (functions must be bound by 'request'). #1506

noseglid opened this issue Mar 25, 2015 · 7 comments · Fixed by #1515

Comments

@noseglid
Copy link

This worked in v2.53.0

var Promise = require('bluebird');
var postAsync = Promise.promisify(require('request').post);

postAsync('http://www.google.com').then(function (content) {
  console.log(content);
});

in v2.54.0, above code gives this error:

Unhandled rejection TypeError: undefined is not a function
    at request.(anonymous function) (/home/alexo/tmp/node_modules/request/index.js:64:16)
    at tryCatcher (/home/alexo/tmp/node_modules/bluebird/js/main/util.js:24:31)
    at ret (eval at <anonymous> (/home/alexo/tmp/node_modules/bluebird/js/main/promisify.js:154:12), <anonymous>:13:23)
    at Object.<anonymous> (/home/alexo/tmp/a.js:4:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Any ideas what changes might've caused this?

@nickmccurdy
Copy link
Contributor

I assume your file is /home/alexo/tmp/a.js?

@noseglid
Copy link
Author

Investigated this a bit more. It seems that request.[verb] now requires it to be bound by 'request'.

This example doesn't work either:

var post = require('request').post;
post('http://www.google.com', function (err, response, body) {
  console.log(body);
});

output:

/home/alexo/tmp/node_modules/request/index.js:65
    return this(params.uri || null, params.options, params.callback)
               ^
TypeError: undefined is not a function
    at request.(anonymous function) (/home/alexo/tmp/node_modules/request/index.js:65:16)
    at Object.<anonymous> (/home/alexo/tmp/a.js:5:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

The promisifying can be solved by doing: var postAsync = Promise.promisify(require('request').post.bind(request)) . Then it works.

@ericlu88
Copy link

+1 for experiencing the same problem. The change seems to be introduced in #1430

@zebateira
Copy link

👍 same here

@noseglid noseglid changed the title Promisifying request.post undefined is not a function (functions must be bound by 'request'). Mar 26, 2015
@simov
Copy link
Member

simov commented Mar 27, 2015

Thanks everyone for the thorough bug report. Fixed here #1515 can you give it a try?

@noseglid
Copy link
Author

@simov 👍 It fixes the issue.

@simov
Copy link
Member

simov commented Mar 27, 2015

Nice! I'll merge it shortly.

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

Successfully merging a pull request may close this issue.

5 participants