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

After the release of v1.0.0-rc.11, Module parse failed: Unexpected token occurs #2545

Closed
ygnoh opened this issue May 23, 2022 · 30 comments
Closed

Comments

@ygnoh
Copy link

ygnoh commented May 23, 2022

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?

@ygnoh ygnoh changed the title After the release of v1.0.0-rc.11, Module parse failed: Unexpected token occurs After the release of v1.0.0-rc.11, Module parse failed: Unexpected token occurs May 23, 2022
@krislavten
Copy link

I have the same issue.

@fb55
Copy link
Member

fb55 commented May 23, 2022

The bundler is choking on export * as DomUtils from "domutils";. It seems like Webpack has supported the export * as ... syntax since ~2020 (see webpack/webpack@3cf8299), 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 umijs/umi#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!

@nicolashu
Copy link

same issue

@mike-lischke
Copy link

mike-lischke commented May 23, 2022

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.

@ygnoh
Copy link
Author

ygnoh commented May 24, 2022

@mike-lischke Do you know a way to lock the package version on lerna?

In my project, enzyme is using cheerio. I couldn't find a way to lock the subdependecy of enzyme.
I tried npm-force-resolutions and overrides. But unfortunately lenra does not support them :(

@ygnoh
Copy link
Author

ygnoh commented May 24, 2022

I resolved this problem by declaring cheerio in devDependencies like:

  "devDependencies": {
    "cheerio": "=1.0.0-rc.3",
    ...

Hope this helps.

@bindoon
Copy link

bindoon commented May 24, 2022

I have the same issue. help me.

image

@gladson1976
Copy link

I've tried the suggestion by @ygnoh, and it works fine in my local build.. but fails in the GitLab pipeline..
anyone have any ideas ?

@yanglbme
Copy link

lock the version in dependencies, like this doocs/md@551b07d

@bindoon
Copy link

bindoon commented May 24, 2022

it seems enzyme is using cherrio, how could I lock cherrio in enzyme

@gladson1976
Copy link

it seems enzyme is using cherrio, how could I lock cherrio in enzyme

lock the cheerio version in your base package.json in dependencies or in devDependencies.. set it to "cheerio": "1.0.0-rc.10"

@gladson1976
Copy link

lock the version in dependencies, like this doocs/md@551b07d

works fine when it is referenced in dependencies.. I had added in the devDependencies earlier..

MarkLark86 added a commit to MarkLark86/superdesk-planning that referenced this issue May 25, 2022
MarkLark86 added a commit to superdesk/superdesk-planning that referenced this issue May 25, 2022
* test: failing client tests

* Limit NodeJS to version 14.19.1

* fix: Slow npm install

* use latest NodeJS v14

* run `npm list`

* ignore `npm list` return code

* lock cheerio version
cheeriojs/cheerio#2545
@ygnoh
Copy link
Author

ygnoh commented May 25, 2022

@yanglbme @gladson1976

As a side note, enzyme recommends locking cheerio version as =1.0.0-rc.3.

enzymejs/enzyme#2559 (comment)

@gladson1976
Copy link

@yanglbme @gladson1976

As a side note, enzyme recommends locking cheerio version as =1.0.0-rc.3.

enzymejs/enzyme#2559 (comment)

Yes, they do.. but since it was working fine for me till Friday with rc.10.. decided to go with it..

@meeksfred
Copy link

I resolved this problem by declaring cheerio in devDependencies like:

  "devDependencies": {
    "cheerio": "=1.0.0-rc.3",
    ...

Hope this helps.

Seriously a life saver, thank you.

@Livshitz
Copy link

+1 on the issue. Caused silent issues during builds. Was discovered only after an exhausting search as a dependency of a sub package, and most frustrating is that it was auto upgraded as rc11 treated as 'patch' (any default ^ package version will do that).
Semantic versioning isn't used by this project?

@francois06
Copy link

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 :

 "resolutions": {
    "cheerio": "1.0.0-rc.10",
    "parse5-htmlparser2-tree-adapter": "^6.0.0"
}

if you use npm, add these lines in package.json :

 "overrides": {
    "cheerio": "1.0.0-rc.10",
    "parse5-htmlparser2-tree-adapter": "^6.0.0"
}

Ressources
https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides
https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/

@fb55
Copy link
Member

fb55 commented Jun 16, 2022

parse5-htmlparser2-tree-adapter is a dual ESM and CJS module and shouldn't need this workaround.

@ljharb
Copy link

ljharb commented Jun 17, 2022

@fb55 the solution seems to be adding to "exports" the deep import enzyme is using.

@Ganesh1991
Copy link

We getting the below issue while creating the build

./node_modules/html-to-react/node_modules/htmlparser2/lib/esm/index.js 67:9
Module parse failed: Unexpected token (67:9)
You may need an appropriate loader to handle this file type.
return getFeed(parseDOM(feed, options));
export * as DomUtils from "domutils"; // Old name for DomHandler
 export { DomHandler as DefaultHandler };

We tried updating both devDependencies and dependencies with "cheerio": "1.0.0-rc.3" But still we are getting same issue

Any suggestions?

@fb55
Copy link
Member

fb55 commented Jul 13, 2022

For everyone that is encountering this, have a look at @lukescott's great writeup on this issue. Relevant here:

A few solutions:

  • Upgrade to webpack 5
  • If you are using babel already, you can use @babel/plugin-proposal-export-namespace-from as mentioned in the webpack issue
  • You can target files/packages that use htmlparser2 and use resolve.mainFields in a rule to tell it to use main instead of module. For us doing this globally broke other things.
  • Lock the dependency to a version that still uses htmlparser2 v7.

I understand that it is annoying to have to work around this issue. Unfortunately, I don't see an easy way to work around this issue without negative side effects for users with modern tooling, meaning that this won't be fixed. Hope that makes sense!

@fb55 fb55 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2022
@ljharb
Copy link

ljharb commented Jul 13, 2022

@fb55 i don't understand - all you have to do is add an entry to "exports", which won't have a negative impact on literally anybody.

Also, not everyone uses bundlers - enzyme runs in node, for example.

@fb55
Copy link
Member

fb55 commented Jul 13, 2022

@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.

@ljharb
Copy link

ljharb commented Jul 13, 2022

Thanks for clarifying.

fwiw, recommending webpack 5 isn't a great idea, because it's broken - it doesn't polyfill node builtins by default.

MarkLark86 added a commit to MarkLark86/superdesk-planning that referenced this issue Oct 28, 2022
* test: failing client tests

* Limit NodeJS to version 14.19.1

* fix: Slow npm install

* use latest NodeJS v14

* run `npm list`

* ignore `npm list` return code

* lock cheerio version
cheeriojs/cheerio#2545
@AnkurPrabhu
Copy link

I resolved this problem by declaring cheerio in devDependencies like:

  "devDependencies": {
    "cheerio": "=1.0.0-rc.3",
    ...

Hope this helps.

Seriously a life saver, thank you.

yes the equal to sign "=" in the statement helped me solve my issue too thankyou

@HondryTravis
Copy link

god

@vlad-frontdev
Copy link

vlad-frontdev commented Dec 28, 2022

Lock the dependency to a version that still uses htmlparser2 v7

Just my 2 cents here basing on this comment. I'm not a cheerio but htmlparser2 user. For me locking htmlparser2 dependency to ~7.0.0 in package.json resolutions did the trick. If you're using Yarn you can try out this.

"resolutions": {
    ...
    "htmlparser2": "~7.0.0"
}

@seanhexl
Copy link

Lock the dependency to a version that still uses htmlparser2 v7

Just my 2 cents here basing on this comment. I'm not a cheerio but htmlparser2 user. For me locking htmlparser2 dependency to ~7.0.0 in package.json resolutions did the trick. If you're using Yarn you can try out this.

"resolutions": {
    ...
    "htmlparser2": "~7.0.0"
}

Can confirm this also worked for me (for me htmlparser2 is coming from sanitize-html, but we also use enzyme on its own). I was testing resolving cheerio and parse5-htmlparser2-tree-adapter, but I no longer need to - resolving htmlparser2 is enough by itself.

@ItzLarz
Copy link

ItzLarz commented Jan 13, 2023

I want to emphasize that this is not a cheerio issue. The issue lies in the newest version (8.0.1) htmlparser2 dependency, which has a file using syntax webpack doesn't understand. So to fix the issue, check if any of your dependencies are using that version of htmlparser2 by running:

npm ls htmlparser2

Revert all those dependencies to previous versions where they use htmlparser2 version 7.2.0 or less.

@fb55
Copy link
Member

fb55 commented Jan 22, 2023

To add to @ItzLarz: Modern versions of Webpack do understand the relevant syntax, so an upgrade will resolve this issue as well. See fb55/htmlparser2#1237 (comment) for more solutions.

zatteo pushed a commit to cozy/coachCO2 that referenced this issue Feb 7, 2024
We need to add the cozy-notifications webpack configuration.
We also need to fix cheerio version to avoid
"export * as DomUtils from "domutils";" error

cheeriojs/cheerio#2545 (comment)
zatteo pushed a commit to cozy/coachCO2 that referenced this issue Feb 8, 2024
We need to add the cozy-notifications webpack configuration.
We also need to fix cheerio version to avoid
"export * as DomUtils from "domutils";" error

cheeriojs/cheerio#2545 (comment)
zatteo pushed a commit to cozy/coachCO2 that referenced this issue Feb 8, 2024
We need to add the cozy-notifications webpack configuration.
We also need to fix cheerio version to avoid
"export * as DomUtils from "domutils";" error

cheeriojs/cheerio#2545 (comment)
zatteo pushed a commit to cozy/coachCO2 that referenced this issue Feb 9, 2024
We need to add the cozy-notifications webpack configuration.
We also need to fix cheerio version to avoid
"export * as DomUtils from "domutils";" error

cheeriojs/cheerio#2545 (comment)
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