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

Broken :nth-child selector #2542

Closed
harimambura opened this issue May 22, 2022 · 5 comments · Fixed by fb55/nth-check#206
Closed

Broken :nth-child selector #2542

harimambura opened this issue May 22, 2022 · 5 comments · Fixed by fb55/nth-check#206

Comments

@harimambura
Copy link

In last version ([1.0.0-rc.11]) selector with :nth-child(n) throws an error "Uncaught TypeError TypeError: getNCheck is not a function", but previous version works fine.

I use the esm package if it matters

@fb55
Copy link
Member

fb55 commented May 22, 2022

I am unable to replicate this:

import { load } from 'cheerio';

console.log(load('<p>1<p>2')('p:nth-child(2)').text()); // 2

You likely have old package versions installed and running a rm -r node_modules package-lock.json before the npm install should resolve things.

@harimambura
Copy link
Author

harimambura commented May 22, 2022

I am unable to replicate this:

import { load } from 'cheerio';

console.log(load('<p>1<p>2')('p:nth-child(2)').text()); // 2

You likely have old package versions installed and running a rm -r node_modules package-lock.json before the npm install should resolve things.

Clear npm cache, create new folder, init npm, set "type": "module" in package.json, next "npm i cheerio"
use the next code to reproduce:
import cheerio from 'cheerio'; const $ = cheerio.load('<html><body><div></div><div></div></body></html>'); $('body > div:nth-child(1)')

I installed cheerio a half an hour ago, this was the first install on my laptop

@fb55
Copy link
Member

fb55 commented May 22, 2022

I am able to replicate now. Turns out a default import to nth-check wasn't available, as that module was still CommonJS. Fix incoming with fb55/nth-check#206

@fb55
Copy link
Member

fb55 commented May 22, 2022

Bumping nth-check to 2.1.0 resolves the issue. That version is already in range for cheerio, so no steps are required here.

@harimambura Thank you for the report!

@eelkevdbos
Copy link

eelkevdbos commented Oct 3, 2024

I'd like to report that - edit: I thought that - this still is broken in version 1.0.0.

image

Edit: I have removed the node_modules and installed freshly with yarn install
Edit 2: I have confirmed that the nth-check version required by cheerio-select is still version 2.0.1 and not 2.1.1
Edit 3: Adding ^2.1.0 as a "resolution" in package.json solves my issues for now
Edit 4: For anyone reading this, you have to remove the yarn cache folder as well to resolve this correctly 👎

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

Successfully merging a pull request may close this issue.

3 participants