Skip to content

Build issue related to html-react-parser #10109

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

Open
PenghaiZhang opened this issue Mar 14, 2025 · 3 comments
Open

Build issue related to html-react-parser #10109

PenghaiZhang opened this issue Mar 14, 2025 · 3 comments

Comments

@PenghaiZhang
Copy link

PenghaiZhang commented Mar 14, 2025

🐛 bug report

After upgrading Parcel from v2.9.x to v2.13.3, my project got a production issue about f is not a constructor.
It works normally in dev environment. I raised this issue in the community of html-react-parser but they suspect this issue is caused by Parcel. It seems the issue is related to whether to minify.

For example, If I do:

import { Text } from 'html-react-parser';

console.log(Text);

The output is undefined in production and the class definition in Devopment.

Image

Image

🎛 Configuration (.babelrc, package.json, cli command)

For production:  cross-env-shell NODE_OPTIONS="--max_old_space_size=4096" parcel build --public-url=. --target mainapp ${npm_package_config_parcelEntryFiles}


For dev: npm run build && cross-env-shell parcel watch --no-autoinstall --public-url=. --target mainappdev ${npm_package_config_parcelEntryFiles}

🤔 Expected Behavior

The use of html-react-parser should not have any issue.

😯 Current Behavior

Getting error about f is not a constructor.

💁 Possible Solution

🔦 Context

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel v2.13.3
Node v22.12.0
npm/Yarn v10.9.0
Operating System Ubuntu 22
@PenghaiZhang
Copy link
Author

PenghaiZhang commented Mar 14, 2025

I also found this error log.

@parcel/transformer-js: Unknown usage of CommonJS `exports` object. This causes tree shaking to be disabled.
  /home/penghai/parcel_test/test/node_modules/html-react-parser/lib/index.js:7:51
    6 | exports.htmlToDOM = exports.domToReact = exports.attributesToProps = exports.Text = exports.ProcessingInstruction = exports.Element = exports.Comment = void 0;
  > 7 | exports.default = HTMLReactParser;
  >   |                                   ^
    8 | var html_dom_parser_1 = __importDefault(require("html-dom-parser"));
    9 | exports.htmlToDOM = html_dom_parser_1.default;
  :memo: Learn more: https://parceljs.org/features/scope-hoisting/#commonjs
@parcel/transformer-js: Unknown usage of CommonJS `exports` object. This causes tree shaking to be disabled.
  /home/penghai/parcel_test/test/node_modules/html-react-parser/lib/index.js:7:28
    6 | exports.htmlToDOM = exports.domToReact = exports.attributesToProps = exports.Text = exports.ProcessingInstruction = exports.Element = exports.Comment = void 0;
  > 7 | exports.default = HTMLReactParser;


@PenghaiZhang
Copy link
Author

There is another error:

@parcel/transformer-js: Conditional or non-top-level `require()` call. This causes the resolved module and all dependencies to be wrapped.

  /home/penghai/parcel_test/test/node_modules/html-dom-parser/lib/client/html-to-dom.js:1:1
  > 1 | "use strict";
  >   | ^
    2 | var __importDefault = (this && this.__importDefault) || function (mod) {
    3 |     return (mod && mod.__esModule) ? mod : { "default": mod };

@PenghaiZhang
Copy link
Author

The issue is probably related to scope hoisting. If I add --no-scope-hoist the issue will disappear. Not sure what has been done since v2.10 to cause this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant