Skip to content

ESM declared as module main field instead of exports #433

Closed
@AndrewLeedham

Description

@AndrewLeedham

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 the package.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions