fb55/htmlparser2

Failed to Compile, with this error.

ns-bc opened this issue ยท 8 comments

ns-bc commented

What could be the cause of this? In a CRA.

./node_modules/htmlparser2/lib/esm/index.js 67:9
Module parse failed: Unexpected token (67:9)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|   return getFeed(parseDOM(feed, options));
| }
> export * as DomUtils from "domutils"; // Old name for DomHandler      
|
| export { DomHandler as DefaultHandler };

same problem

+1

Was facing the same issue. It seems to be the issue with the latest version. A quick workaround is to fix the version of htmlparser2 in your package json and re-run npm install cmd. So It won't update the package version to latest.

export * as ns is a later extension of the module syntax and is supported in webpack 5.

See webpack/webpack#10460

I ran into this because:

  • Our projects are still using webpack 4
  • We are using html-to-react, which updated from htmlparser2 7 to 8 between 1.4 and 1.5 and we are using ^.

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.
fb55 commented

Thanks for the great write up @lukescott! I understand that this is annoying for everyone affected.

This change was part of a major version, which does allow for breaking changes. I don't see an easy way to work around this issue without negative side effects for users with modern tooling, so unfortunately this won't be fixed. Hope that makes sense!

Isnโ€™t the easy fix to do it in two lines?