Closed
Description
Expected Behavior
When using ESM with import { attributesToProps } from 'html-react-parser';
it should import the index.mjs
entry, and attributesToProps
should be a function.
Actual Behavior
It instead tries to import index.js
and fails with:
SyntaxError: Named export 'attributesToProps' not found. The requested module 'html-react-parser' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'html-react-parser';
const { attributesToProps } = pkg;
Potential Solution
The package currently uses "module": "index.mjs"
, the ESM spec has since use "exports": "./index.mjs"
. So the solution would be to swap module
for exports
, or leave module
in I suppose for backwards compatibility?
Steps to Reproduce
- Create a ESM project e.g:
"type": "module
in thepackage.json
. - Install
html-react-parser
. - Create a file along the lines of
import { attributesToProps } from 'html-react-parser';
Reproducible Demo
Not 100% if those platforms support ESM.
Environment
- Version: 1.2.7
- Platform: macOS Big Sure 11.2.3
- Browser: Chromium 97