Fix exports for projects consuming this package as an ES module#481
Merged
Conversation
jonathonherbert
approved these changes
May 19, 2026
jonathonherbert
left a comment
Contributor
There was a problem hiding this comment.
Oh this is interesting, looks like module was a proposal that didn't end up being adopted. Glad there's a standard now 😅 thanks for the PR!
Contributor
Author
|
Unfortunately this still can't be consumed as an ES Module, because the import paths don't use the full filename (i.e. they don't end with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change?
Adjusts exports in package.json. The
moduleproperty specified here does not seem to be part of the official Node.js spec. I've noticed that when using vitest, this has led to custom elements not being correctly set up and tests failing—possibly because it tries to import the CommonJS paths provided as if they were ESM. It is possible that in the future, if our projects use a different bundling system, this could cause similar errors in the actual apps at runtime.The
mainproperty is left as is, in case this package is consumed by tooling that doesn't use theexportsproperty.See "conditional exports" in https://nodejs.org/docs/latest/api/packages.html for more info.
How to test
I have tested this locally by manually editing
node_modules/@guardian/prosemirror-elements/package.jsonwith matching changes in a downstream project (Composer). We could test further by doing a "prerelease" but I think this is low risk enough that we could merge, and then revert the changes if problems are found.How can we measure success?
ES module compatibility!
Have we considered potential risks?
There's an unlikely, but non-zero possibility that this will interact strangely with bundlers used in downstream projects.