-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Solved "Cannot read property 'parent' of undefined" #707
Conversation
Please add tests. :) |
I'm sorry, but I'm noob to NodeJs. |
Can you share the code that triggered the error? We need to understand the bug that you are trying to fix, and then we'll want to be sure it doesn't come back. |
@jugglinmike I've faced this bug with these conditions: |
@inDream I'm not sure those examples qualify as "bugs" because they describe undocumented usages of the I might be wrong, though--can you give some context as to why you would like to use |
@jugglinmike If load data from remote endpoint, network problem would cause this bug. I have no idea why this would happen as I haven't log the response content. Maybe there's other case would cause this bug but this is only one of the example and I haven't test this whether would fix the bug. |
@inDream If the data source is unreliable, you might consider doing some explicit error checking in your application logic prior to invoking |
@jugglinmike This is a better approach but my concern is the error message is not clear. |
@inDream Fair enough. The solution to your problem would take a completely different form than the patch provided here, though. Because it concerns an undocumented usage of the API, the fix is low-priority, but I would welcome a patch. |
Hi, TypeError: Cannot read property 'parent' of undefined |
Could you provide a small, self-contained example, @chubaka? |
// I have the same issue. Here is an example. var url = 'http:/www.msn.com'; |
This code is working for me. const request = require('request');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
function getDOM(url) {
return new Promise(function (resolve, reject) {
request({ uri: url, encoding: null }, function (err, res, html) {
if (err) {
reject(err);
} else {
html = iconv.decode(html, 'ISO-8859-1');
resolve(cheerio.load(html));
}
});
});
} |
Closing this as it is still missing a test case. If someone is able to provide one I am happy to reopen it. |
TypeError: Cannot read property 'parent' of undefined |
help me |
Could you provide the HTML and the code that is causing that behavior? |
Solving this:
parse.js: at line 55
var oldParent = node.parent || node.root,
^
TypeError: Cannot read property 'parent' of undefined