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

"TypeError: Cannot read property '0' of undefined" during clone using Parcel #588

Closed
raoulmillais opened this issue Nov 23, 2018 · 8 comments

Comments

@raoulmillais
Copy link

raoulmillais commented Nov 23, 2018

I am following the browser example and I get an error on this line in GitCommit

Uncaught (in promise) TypeError: Cannot read property '0' of undefined

If I npm link a clone of the isomorphic-git repo and log out the headers variable it is an array of strings. Have I stumbled on a bug?

These are the headers:

["tree f796b167fe72560d513ddab9321141dd539d6d47", "parent 0793e27", "author William Hilton wmhilton@gmail.com 1542241548 -0500", "committer GitHub noreply@github.com 1542241548 -0500", "gpgsig -----BEGIN PGP SIGNATURE-----", " ", " wsBcBAABCAAQBQJb7L0MCRBK7hj4Ov3rIwAAdHIIAKS41E6rLOz3acKlh5ZJ25VV", " JHrD5yPb/I+bjQVz9kR2+nVTfaDaciHfu+3mVHgM90b8hstzY36cEq5RaaMrrwzH", " Z1XeFG81kezc3tG/TWIwbE2xQ8S+hwO/rBZJ7814PuM10/CpUSx7qfsgCjRXTKJi", " iTkDuv+yrlHeg+Ixja3CrrAtlBlGCJB0H8RndOr7QcTmtSNZBkyNv39egaR7WjNM", " 5JbYDEAcX1BnuthiN0IQhBtXsert25DoAqb4C/GJv9GeAYGCo7/5ReinvyTy28Gp", " gO1uDojhOkvnuOKztMwcn/HgfUGKDB/eFnRccRehXi9LcXswqc6U3x8R0C1QLxg=", " =TMTS", " -----END PGP SIGNATURE-----", " "]

adding a console.log statement inside the loop over the normalised headers and the problem goes away ¯\_(ツ)_/¯

@billiegoose
Copy link
Member

Hmm... that's interesting. I haven't seen that error before! I don't have enough information to reproduce the error yet. What example are you running exactly? And what browser were you using?

@raoulmillais
Copy link
Author

raoulmillais commented Nov 24, 2018

Thanks for getting back to me @wmhilton. Sorry I was tired last night after spending half a day trying to get this working and failed to give you all the information you need to help! I should have mentioned that I am using parcel.js (with babel configured for babel-preset-env) to bundle an index file which contains almost exactly what is in the browser tutorial. I have created a minimal gist that reproduces the issue

npm install && npm start if you clone the gist

I am running:

  • MacOSX Mojave 10.14.1
  • Latest chrome (Version 70.0.3538.110 (Official Build) (64-bit)

@billiegoose
Copy link
Member

Awesome! I'll investigate this today. I have a sneaking suspicion (given that adding a console.log "fixed" it) that it may be a bug in the transpiler (parcel, or babel, or uglify) but if I can reproduce it and figure out how to fix it without adding a console.log that'll be ideal!

@billiegoose
Copy link
Member

This is officially really weird. AFAICT it's probably a bug in parcel related to the infamous babel "regenerator-runtime". It seems to be transpiling my simple "for (h of hs)" loop into something else. I just can't figure out what.

@billiegoose
Copy link
Member

Aha. Firefox shows the actual error and the transpiled JS that parcel's created:

Unhandled promise rejection TypeError: "_e10 is undefined"
        }, {
          key: "parseHeaders",
          value: function parseHeaders() {
            var t = c.justHeaders(this._commit).split("\n"),
                e = [];
            var _iteratorNormalCompletion13 = true;
            var _didIteratorError13 = false;
            var _iteratorError13 = undefined;

            try {
              for (var _iterator13 = t[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
                var _r7 = _step13.value;
                " " === _r7[0] ? e[e.length - 1] += "\n" + _r7.slice(1) : e.push(_r7);
              }
            } catch (err) {
              _didIteratorError13 = true;
              _iteratorError13 = err;
            } finally {
              try {
                if (!_iteratorNormalCompletion13 && _iterator13.return != null) {
                  _iterator13.return();
                }
              } finally {
                if (_didIteratorError13) {
                  throw _iteratorError13;
                }
              }
            }

            var r = {
              parent: []
            };

            for (var _i2 = 0; _i2 < e.length; _i2++) {
  /*HERE*/    var _t12 = _e10[_i2];

              var _e10 = _t12.slice(0, _t12.indexOf(" ")),
                  _n4 = _t12.slice(_t12.indexOf(" ") + 1);

              Array.isArray(r[_e10]) ? r[_e10].push(_n4) : r[_e10] = _n4;
            }

            return r.author && (r.author = Object(u.a)(r.author)), r.committer && (r.committer = Object(u.a)(r.committer)), r;
          }
        }, {

Hmm.

@billiegoose
Copy link
Member

Well, you might not like this answer but I found one potential "solution". Problem goes away if you add this to your package.json so parcel doesn't transpile so aggressively:

  "browserslist": [
    "last 2 Chrome versions"
  ]

With some experimenting, I found even this works if you want to be more conservative:

  "browserslist": [
    "> 3%"
  ]

Parcel defaults to > 0.25% "(Meaning, support every browser that has 0.25% or more of the total amount of active web users)" which is probably an unrealistic support goal for an application using isomorphic-git anyway.

I know this is not super satisfying - I too am now curious what I did that causes Babel (or something) to lose track of the scope of hs - it looks to me like _e10 should in fact be e. But let me know if this solution works for you and I can close this ticket, or if we need to find another solution.

@billiegoose billiegoose changed the title Error in GitCommit on cloning "TypeError: Cannot read property '0' of undefined" during clone using Parcel Nov 24, 2018
@billiegoose
Copy link
Member

I'm renaming the issue to make it more Googleable. I doubt you'll be the last person to run into this weird error.

@raoulmillais
Copy link
Author

Awesome. Thanks for your help @wmhilton Your solution works well and is fine for my needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants