cheerio: After the release of `v1.0.0-rc.11`, `Module parse failed: Unexpected token` occurs
As the title says, since v1.0.0-rc.11 the below error occurs:
START:
ℹ 「wdm」: Compiled successfully.
ℹ 「wdm」: Compiling...
✖ 「wdm」:
ERROR in ./node_modules/htmlparser2/lib/esm/index.js 59:9
Module parse failed: Unexpected token (59:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| return getFeed(parseDOM(feed, options));
| }
> export * as DomUtils from "domutils";
| // Old name for DomHandler
| export { DomHandler as DefaultHandler };
@ ./node_modules/cheerio/lib/esm/index.js 11:0-68
@ ./node_modules/enzyme/build/ReactWrapper.js
@ ./node_modules/enzyme/build/index.js
@ ./test.entry.js
I think it’s a bug of cheerio, because it has been occurring since 3 days ago when the v1.0.0-rc.11 released.
Could you please look into this bug?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 22
- Comments: 30 (5 by maintainers)
Commits related to this issue
- fix: lock cheerio version — committed to doocs/md by yanglbme 2 years ago
- lock cheerio version https://github.com/cheeriojs/cheerio/issues/2545 — committed to MarkLark86/superdesk-planning by MarkLark86 2 years ago
- fix(ci): Lock cheerio version to 1.0.0-rc10 (#1687) * test: failing client tests * Limit NodeJS to version 14.19.1 * fix: Slow npm install * use latest NodeJS v14 * run `npm list` * ig... — committed to superdesk/superdesk-planning by MarkLark86 2 years ago
- fix(ci): Lock cheerio version to 1.0.0-rc10 (#1687) * test: failing client tests * Limit NodeJS to version 14.19.1 * fix: Slow npm install * use latest NodeJS v14 * run `npm list` * ig... — committed to MarkLark86/superdesk-planning by MarkLark86 2 years ago
- chore: Fix build after cozy-notifications installation We need to add the cozy-notifications webpack configuration. We also need to fix cheerio version to avoid "export * as DomUtils from "domutils";... — committed to cozy/coachCO2 by cballevre 5 months ago
- chore: Fix build after cozy-notifications installation We need to add the cozy-notifications webpack configuration. We also need to fix cheerio version to avoid "export * as DomUtils from "domutils";... — committed to cozy/coachCO2 by cballevre 5 months ago
- chore: Fix build after cozy-notifications installation We need to add the cozy-notifications webpack configuration. We also need to fix cheerio version to avoid "export * as DomUtils from "domutils";... — committed to cozy/coachCO2 by cballevre 5 months ago
- chore: Fix build after cozy-notifications installation We need to add the cozy-notifications webpack configuration. We also need to fix cheerio version to avoid "export * as DomUtils from "domutils";... — committed to cozy/coachCO2 by cballevre 5 months ago
I resolved this problem by declaring
cheerioindevDependencieslike:Hope this helps.
People might not be able to upgrade a library, if that’s actually brought in by other modules (e.g. via create-react-app). Changes that require upgrades of other libraries should always be accompanied by at least a minor version increase.
Locking package import to cheerio@1.0.0-rc.10 fixed the issue for me. But that should really not be needed! Please do such changes in another release that raise at least the minor version number, so they are not automatically picked up.
1.0.0-rc.11 is an issue for me because of the ECMAScript Modules used in parse5-htmlparser2-tree-adapter 7.0.0 …
The breaking change on parse5-htmlparser2-tree-adapter v7 is well documented : https://github.com/inikulin/parse5/releases/tag/v7.0.0
This is a shame, that this package (cheerio) bump its dependencies (with major change) without a major change on its version … It cost me hours of debugging -_-
How i landed here ? I’m here because cheerio is a dependencies of an dependencies of MJML (that I use)! (I remove node_modules and when I yarn install again because people do not handle correct semver everything explode)
Spend hours to find this => MJML > mjml-core > juice > “cheerio”: “^1.0.0-rc.10” > parse5-htmlparser2-tree-adapter 7.0.0
Cheerio go to 1.0.0-rc.11 with parse5 v7 ==> all lib which use “cheerio”: “^1.0.0-rc.10” will potentially blow up …
So, please next time read the changelog before up the dep…
Meanwhile, here my fix :
if you use yarn, add these lines in package.json :
if you use npm, add these lines in package.json :
Ressources https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/
Just my 2 cents here basing on this comment. I’m not a
cheeriobuthtmlparser2user. For me lockinghtmlparser2dependency to~7.0.0inpackage.jsonresolutionsdid the trick. If you’re using Yarn you can try out this.@mike-lischke Do you know a way to lock the package version on
lerna?In my project,
enzymeis usingcheerio. I couldn’t find a way to lock the subdependecy ofenzyme. I triednpm-force-resolutionsandoverrides. But unfortunatelylenradoes not support them 😦I want to emphasize that this is not a
cheerioissue. The issue lies in the newest version (8.0.1)htmlparser2dependency, which has a file using syntaxwebpackdoesn’t understand. So to fix the issue, check if any of your dependencies are using that version ofhtmlparser2by running:Revert all those dependencies to previous versions where they use
htmlparser2version 7.2.0 or less.I have the same issue. help me.
To add to @ItzLarz: Modern versions of Webpack do understand the relevant syntax, so an upgrade will resolve this issue as well. See https://github.com/fb55/htmlparser2/issues/1237#issuecomment-1182522861 for more solutions.
god
@yanglbme @gladson1976
As a side note,
enzymerecommends lockingcheerioversion as=1.0.0-rc.3.https://github.com/enzymejs/enzyme/issues/2559#issuecomment-1133812922
Can confirm this also worked for me (for me
htmlparser2is coming fromsanitize-html, but we also useenzymeon its own). I was testing resolvingcheerioandparse5-htmlparser2-tree-adapter, but I no longer need to - resolvinghtmlparser2is enough by itself.yes the equal to sign “=” in the statement helped me solve my issue too thankyou
@ljharb This is actually a separate issue 😄 — #2547 was fixed in #2601, which is included in the latest release. The issue here is that some old (but not too old) Webpack versions will struggle with
export * as X from 'y'in the ESM module.parse5-htmlparser2-tree-adapteris a dual ESM and CJS module and shouldn’t need this workaround.works fine when it is referenced in dependencies… I had added in the devDependencies earlier…
lock the version in dependencies, like this https://github.com/doocs/md/commit/551b07d46df7136e5758b418a62bcec3c9bb52f5
The bundler is choking on
export * as DomUtils from "domutils";. It seems like Webpack has supported theexport * as ...syntax since ~2020 (see https://github.com/webpack/webpack/commit/3cf8299602b468ae0291779cd57c7fed3037b7f6), and an update should fix things. Alternatively, you could also force the bundler to pick up the CommonJS code that’s still shipped with Cheerio.For https://github.com/umijs/umi/issues/8109: umijs seems to have switch to rollup afaict (at least I haven’t been able to find a Webpack version), so there is a chance that updating some internal packages might do the trick?
Please let me know if this makes sense!