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 'children' of undefined #804

Closed
binarykitchen opened this issue Jan 26, 2016 · 5 comments
Closed

TypeError: Cannot read property 'children' of undefined #804

binarykitchen opened this issue Jan 26, 2016 · 5 comments

Comments

@binarykitchen
Copy link

/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/cheerio/lib/api/traversing.js:10
    return memo.concat(_.filter(elem.children, isTag));
                                    ^

TypeError: Cannot read property 'children' of undefined
    at /home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/cheerio/lib/api/traversing.js:10:37
    at /home/michael-heuberger/Development/videomail.io/node_modules/lodash/lodash.js:779:11
    at /home/michael-heuberger/Development/videomail.io/node_modules/lodash/lodash.js:3923:15
    at baseReduce (/home/michael-heuberger/Development/videomail.io/node_modules/lodash/lodash.js:776:5)
    at Function.reduce (/home/michael-heuberger/Development/videomail.io/node_modules/lodash/lodash.js:7836:14)
    at exports.find (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/cheerio/lib/api/traversing.js:9:17)
    at module.exports (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/cheerio/lib/cheerio.js:86:18)
    at new initialize (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/cheerio/lib/static.js:26:20)
    at initialize (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/cheerio/lib/static.js:23:14)
    at DestroyableTransform._transform (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/index.js:54:34)
    at DestroyableTransform.Transform._read (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:10)
    at DestroyableTransform.Transform._write (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:160:12)
    at doWrite (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:335:12)
    at writeOrBuffer (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:321:5)
    at DestroyableTransform.Writable.write (/home/michael-heuberger/Development/videomail.io/node_modules/robots-generator/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:248:11)
    at write (/home/michael-heuberger/Development/videomail.io/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
@jugglinmike
Copy link
Member

Thanks for the report! We'll need more information before we're able to help you. Can you share the HTML that is causing Cheerio to throw this error? Please remove any text that is not necessary to reproduce the problem.

@pat-eason
Copy link

I can confirm this is happening, ran into it after upgrading to 0.19.0 today. Small demo fails:

const cheerio = require('cheerio');
var $ = cheerio.load('<a href="1">one</a><a href="2">two</a><a href="3">three</a>');
$('a');  // <-- Results in error at line

Any selectors I try fail with the same TypeError: Cannot read property 'children' of undefined response.

@binarykitchen
Copy link
Author

@jugglinmike I am afraid this one is difficult to reproduce. It just happened when I upgraded lodash from v3.x to v4.x which is quite a rad change.

Why don't you add an undefined check on that element?

@jugglinmike
Copy link
Member

@CoastalP47 Thanks for the script, but it's not producing an error for me. Maybe it was resolved in one of this project's dependencies? If you have a moment, could you try re-installing Cheerio and seeing if it still fails? If so, the output of npm ls may be relevant.

@binarykitchen that change would fix the immediate problem, but we need to understand the problem before we try to solve it. A failing test case would help us avoid regressions and might even highlight a more fundamental issue.

@rugarcialopez
Copy link

I've got the same issue as @binarykitchen when I upgraded Lodash from v2.x to v4.x. Also I've updated cheerio to 0.20.0 and I am still getting the issue. Any ideas??

@fb55 fb55 closed this as completed Oct 15, 2020
rdoproject pushed a commit to rdo-packages/tripleo-ui-distgit that referenced this issue Apr 4, 2024
Patch Set 1:

It looks like this: cheeriojs/cheerio#804

Patch-set: 1
Reviewer: Gerrit User 504 <504@270e2033-b340-4cff-9539-693957ebf0e7>
Label: Code-Review=0
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

5 participants