Cheerio: Cannot read property 'htmlparser2' of undefined (v1.0.0)

Created on 14 Dec 2018  路  7Comments  路  Source: cheeriojs/cheerio

I am getting the following error when using the latest version of cheerio.

TypeError: Cannot read property 'htmlparser2' of undefined
    at parseWithParse5 (webpack-internal:///../../packages/web-isomorphic/node_modules/cheerio/lib/parse.js:26:64)
    at Function.exports.evaluate (webpack-internal:///../../packages/web-isomorphic/node_modules/cheerio/lib/parse.js:42:68)
    at module.exports (webpack-internal:///../../packages/web-isomorphic/node_modules/cheerio/lib/parse.js:11:21)
    at Function.exports.load (webpack-internal:///../../packages/web-isomorphic/node_modules/cheerio/lib/static.js:27:14)
    at eval (webpack-internal:///./node_modules/@reactant/web-isomorphic/lib/ServerApp.js:96:37)
    at Generator.next (<anonymous>)
    at step (webpack-internal:///./node_modules/@reactant/web-isomorphic/lib/ServerApp.js:60:191)
    at eval (webpack-internal:///./node_modules/@reactant/web-isomorphic/lib/ServerApp.js:60:361)
    at <anonymous>

I traced the source of the issue to the following line of code.

https://github.com/cheeriojs/cheerio/blob/v1.0.0/lib/parse.js#L27

This really caught me off-guard because the v1.0.0-rc version started downloading instead of the stable version I was using. A release candidate should NEVER be tagged as latest.

All 7 comments

Please look at #1261

Currently, I'm using the following hacky workaround . . .

const $ = cheerio.load(indexHtml, { _useHtmlParser2: true });

Hm, that's a bit strange, I just downloaded rc2 today and it loads fine for me (in node.js).

If you prefer to use htmlparser2 the future-proof way to do this is:

const dom = htmlparser2.parseDOM(file.contents, options)
const $ = cheerio.load(dom)

I assume this is fixed

blimey!!!

I don't think it's fixed, not for me at least. His referenced issue is related to semver of this package

I still get this error with Enzyme

enzyme@^3.11.0:
  version "3.11.0"
  resolved "https://artifacts-prod-use1.pinadmin.com/artifactory/api/npm/node-npm-yarn-prod-virtual/enzyme/-/enzyme-3.11.0.tgz#71d680c580fe9349f6f5ac6c775bc3e6b7a79c28"
  integrity sha1-cdaAxYD+k0n29axsd1vD5rennCg=
  dependencies:
    array.prototype.flat "^1.2.3"
    cheerio "^1.0.0-rc.3"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

chenweiyj picture chenweiyj  路  5Comments

askie picture askie  路  4Comments

robogeek picture robogeek  路  4Comments

collegepinger picture collegepinger  路  3Comments

clayrisser picture clayrisser  路  4Comments