Apify and Crawlee Official Forum

Updated 4 months ago

Error in crawlee import: `Module '"cheerio"' has no exported member 'Element'`

After running npm run build on version 3.11.1 of Crawlee, I get the error below:

Plain Text
node_modules/.pnpm/@crawlee+playwright@3.11.1_playwright@1.46.1/node_modules/@crawlee/playwright/internals/adaptive-playwright-crawler.d.ts:7:29 - error TS2305: Module '"cheerio"' has no exported member 'Element'.

7 import { type Cheerio, type Element } from 'cheerio';
                              ~~~~~~~


Found 1 error in node_modules/.pnpm/@crawlee+playwright@3.11.1_playwright@1.46.1/node_modules/@crawlee/playwright/internals/adaptive-playwright-crawler.d.ts:7

I have seen other posts in channels here with the same issue, but there doesn't seem to be a known workaround or solution. Can anyone advise what has broken in the latest version? This error seems to be coming from the package itself, not from user code. I am not using any Cheerio crawling.
c
M
W
6 comments
On further digging, it looks like this is due to the v1.0.0 release of Cheerio, which removed the ability to use (previously deprecated) imports. I have manually fixed the import in my node_modules, but this should be fixed asap (it's only 1 type that needs to be changed to cheerio.Cheerio instead of just Cheerio after fixing the import statement.
Thank you for your feedback, I will report this.
This is a known problem of Cheerio which will be addressed in a future Crawlee update by pinning the RC version of Cheerio and waiting for them to fix this. Crawlee beta already does this. Alternatively, you could use npm overrides to set the Cheerio version explicitly.
Crawlee 3.11.2 is out with the pinned version
show me your package.json but probably the problem lies with how you install your packages (not taking packages from lock file but re-isntalling them - therefore updating dependecies of dependencies - happens a lot with Crawlee to be honest.

On their Github discussion was mentioned similar problem and their solution to that was to install with --force flag(!))


add this to you package json

Plain Text
 "overrides": {
    "got-scraping": "4.0.5", // that is not neccesary - it was for other similiar problem with crawlee https://github.com/apify/crawlee/discussions/2515
    "cheerio": "1.0.0-rc.12" // FIX THIS ISSUE
  },


Thanks, yeah I worked out the override and pinned the cheerio rc - I understand the beta versions of crawlee are pinning this version internally too
Add a reply
Sign up and join the conversation on Discord