Skip to content

Publish ES modules #437

Closed
Closed
@IanVS

Description

@IanVS

Describe the feature you'd like:

I am a maintainer of storybook-builder-vite, which allows storybook users to build their previews using vite, which works entirely in ESM. Storybook recently also released @storybook/jest and the latest release extends expect with jest-dom matchers. However, since jest-dom is only published as commonjs, typescript needs to add a compatibility layer so that import * as matchers from @testing-library/jest-dom/matchers; can be used. This is causing an issue, whereby a default is being included as well, causing expect to throw an error. See storybookjs/jest#15 (comment) for the error description.

To avoid the esm/cjs bundling problems, I'd like to request that jest-dom publish an esm version alongside cjs.

Suggested implementation:

I see that you're using kcd-scripts build, which also allows a --bundle flag that builds cjs, esm, umd, and umd.min bundles. Alternatively, https://github.com/unjs/unbuild is a very simple build tool which can generate multiple targets.

Describe alternatives you've considered:

I'm trying to troubleshoot the symptom of the esm->cjs namespace import to see if there's a way I can work around it in the storybook packages, but I think it would be nice if this package could publish esm anyway, especially now that jest itself is publishing es modules.

Teachability, Documentation, Adoption, Migration Strategy:

I think as long as the package.json is updated correctly, there shouldn't be any user-facing changes needed. That said, bundling the files as suggested above will cause problems if users are importing files directly from node_modules/@testing-library/jest-dom/dist. If that's the case, and it's a use case that needs to be supported, then a different build process will be needed, but can still be accomplished.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions