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

content.ForEach is not a function #1591

Closed
mrjackyliang opened this issue Dec 24, 2020 · 9 comments
Closed

content.ForEach is not a function #1591

mrjackyliang opened this issue Dec 24, 2020 · 9 comments

Comments

@mrjackyliang
Copy link

mrjackyliang commented Dec 24, 2020

Hello, I am a developer of a Homebridge plugin, and I am having a user report this error:

[12/23/2020, 4:09:41 PM] TypeError: content.forEach is not a function
    at parse (/homebridge/node_modules/homebridge-adt-pulse/node_modules/cheerio/lib/parse.js:38:15)
    at Function.exports.load (/homebridge/node_modules/homebridge-adt-pulse/node_modules/cheerio/lib/static.js:39:14)
    at /homebridge/node_modules/homebridge-adt-pulse/api.js:598:39
    at arrayMap (/homebridge/node_modules/homebridge-adt-pulse/node_modules/lodash/lodash.js:639:23)
    at Function.map (/homebridge/node_modules/homebridge-adt-pulse/node_modules/lodash/lodash.js:9580:14)
    at Request._callback (/homebridge/node_modules/homebridge-adt-pulse/api.js:597:28)
    at Request.self.callback (/homebridge/node_modules/homebridge-adt-pulse/node_modules/request/request.js:185:22)
    at Request.emit (events.js:315:20)
    at Request.<anonymous> (/homebridge/node_modules/homebridge-adt-pulse/node_modules/request/request.js:1154:10)
    at Request.emit (events.js:315:20)
[12/23/2020, 4:09:41 PM] Got SIGTERM, shutting down Homebridge...

More details in this issue

@5saviahv
Copy link
Contributor

5saviahv commented Dec 24, 2020

Cheerio.load expects there to be array. Older versions was there condition for checking, if it is not array. Seems like it is lost due to optimizations.

@mrjackyliang
Copy link
Author

Yeah, the input is an array. I don't get why it's having this error.

@5saviahv
Copy link
Contributor

sample from your code where it happens

...
const $ = cheerio.load(body);
const sensors = $('#orbSensorsList table tr.p_listRow').toArray();

const output = _.map(sensors, (sensor) => {
  const theSensor = cheerio.load(sensor);
  const theName = theSensor('a.p_deviceNameText').html();
  ...
})
...

variable sensor is single object (html node)

older version wraps it into array

@mrjackyliang
Copy link
Author

Oh haha! Totally missed that actually.

@mrjackyliang
Copy link
Author

Screen Shot 2020-12-24 at 3 29 21 PM

Hmm could be the types need to be changed also, but yes, your suggestion works.

@fb55
Copy link
Member

fb55 commented Dec 25, 2020

Thanks for the report! This was already fixed in 0855be6, which should be part of a new release soon.

@boycce
Copy link

boycce commented Feb 4, 2021

@fb55 thanks the fix works for me when sourcing the public repository.

Our implementation:

// v1.0.0-rc.5
$("table[table] tr").each((index, element) => {
   let issueHere = cheerio.load(element)
   // ...

@5saviahv 5saviahv mentioned this issue Feb 26, 2021
@facundofarias
Copy link

Hello, any news about when this fix will be released?

@MegEdnazednav
Copy link

MegEdnazednav commented Mar 9, 2021

Hello, we are recently encountering this issue in our application as well, coming from a dependency that we are using. Could you tell us when the new version with the fix will be released?
Thanks!

@fb55 fb55 mentioned this issue Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants