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

Uncaught TypeError: undefined is not a function in github.js:32 #49

Closed
DineshGK opened this issue Apr 10, 2013 · 15 comments
Closed

Uncaught TypeError: undefined is not a function in github.js:32 #49

DineshGK opened this issue Apr 10, 2013 · 15 comments

Comments

@DineshGK
Copy link

While call write/read methods it show error like: Uncaught TypeError: undefined is not a function in github.js:32
i try like this bellow...
repo.read('master', 'README.md', function(err, data) {});
repo.write('master', ' Test/README.md ', 'This is my New comment', '1st commit', function(err) {});

@dctr
Copy link

dctr commented Apr 15, 2013

Line 32 is

  var xhr = new XMLHttpRequest();

The new code regards node.js:

if (typeof exports !== 'undefined') {
  var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
  var _ = require('underscore');
}

If i comment this out, the error is gone. Strangely i get this:

console.log(typeof exports); // undefined

However there is nothing wrong with my XHR, it works fine in other apps!

@michael
Copy link
Collaborator

michael commented Apr 15, 2013

Just did a quick fix. Please check if it works now.

@dctr
Copy link

dctr commented Apr 15, 2013

nope, does not work.

furthermore: is this bound to the global object here? if yes, it does not change anything. if no, the code should not work with node.js anymore.

@michael
Copy link
Collaborator

michael commented Apr 15, 2013

this is bound to the global, which is either window (in the browser) or global (in Node.js).

So this code:

if (typeof this.exports !== 'undefined') {
    var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
    var _ = require('underscore');
}

should only be executed for the Node.js environment.

@dctr
Copy link

dctr commented Apr 15, 2013

as it shouldn't be executed for the browser, as window does not have exports. nevertheless it gets executed. i lack a good explanation too...

@michael
Copy link
Collaborator

michael commented Apr 15, 2013

Exactly. Strange, just included the file and it works fine.

@dctr
Copy link

dctr commented Apr 15, 2013

OK, some debug info: Firefox 20.0.1 64-bit Linux

@AmGK
Copy link

AmGK commented Apr 16, 2013

Hi all,

This code work for me...

  if(window.ActiveXObject) {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if(window.XMLHttpRequest) {
      xhr = new window.XMLHttpRequest();
  }

@dctr
Copy link

dctr commented Apr 16, 2013

This issue is about node.js compatibility, not IE compatibility...

@AmGK
Copy link

AmGK commented Apr 18, 2013

Ok...But one more problem i am facing Guys..
For getting the Github object i write the code like follows
var github = new Github({
token: "08efd4412af3bffba593c",
auth: "oauth"
});

In the above code i want pass the toke dynamically for every individual github login user..How can i do this..
means How do i get github login user token.

Any appreciated answer ...
Thanks

@ixtli
Copy link

ixtli commented May 9, 2013

Doesn't work on chrome 26.0.1410.65 either.

var XMLHttpRequest = at the top of github.js isn't getting hit until after var xhr = new XMLHttpRequest(); so that variable has yet to be defined.

for what it's worth im doing the following:

this.github = new Github({
    username: user,
    password: pass,
    auth: "basic"
});

this.github.getUser().repos(function (err, repos) {
    console.log(err); console.log(repos);
});

and getting this error immediately. i fixed it by simply changing line 32 to var xhr = new window.XMLHttpRequest(); which i know doesn't work for IE. but, well, i don't really care about supporting IE for my purposes 👍

@holsted
Copy link
Contributor

holsted commented May 11, 2013

I'm having the same issue.

Chrome 26.0.1410.65 and Mountain Lion v10.8.3

var github = new Github({
    token: "my_oauth_token",
    auth: "oauth"
});

var user = github.getUser();
var myRepos = user.repos(function(err, repos) {
    console.log(repos);
});

results in the same error, Uncaught TypeError: undefined is not a function.

@mattwkelly
Copy link

@FajitaNachos change line 32 from

xhr = new XMLHttpRequest();

to

xhr = new window.XMLHttpRequest();

@w35l3y
Copy link

w35l3y commented May 21, 2014

☝️

Was it fixed already? 'Cause it is working for me just fine.

punchagan pushed a commit to punchagan/github that referenced this issue Aug 23, 2014
@ingalls
Copy link
Collaborator

ingalls commented Dec 11, 2014

I am not able to reproduce this error either. Please open a new issue if this error comes up again.

@ingalls ingalls closed this as completed Dec 11, 2014
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

9 participants