Skip to content
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

fix CJS & ESM distribution #17

Merged
merged 1 commit into from
Jan 16, 2022

Conversation

JakobJingleheimer
Copy link
Contributor

@JakobJingleheimer JakobJingleheimer commented Jan 4, 2022

Summary

Previously, react-merge-refs was distributing both CJS and ESM, which is unnecessary (ESM can import CJS just fine). Additionally the package.json was not properly configured to publicise the ESM distribution.

Now, only CJS is built and distributed, and package.json properly publicises both for use by either CJS or ESM.

Fixes #16

Test plan

These should both return { default: [Function: mergeRefs] } (they fail on main, but succeed on this branch).

$ node \
--input-type=module \
-e "import mergeRefs from 'react-merge-refs'; console.log(mergeRefs)"
$> node \
--input-type=commonjs \
-e "const mergeRefs = require('react-merge-refs'); console.log(mergeRefs)"

This should not be a breaking change.

@gregberge gregberge merged commit 048c4ea into gregberge:main Jan 16, 2022
@JakobJingleheimer JakobJingleheimer deleted the fix-packagejson-exports branch January 16, 2022 16:58
@Benjamin-Willard
Copy link

FYI this merge broke.

Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module D:\@blender\suicideleague\@app\node_modules\react-merge-refs\dist\index.mjs not supported.
Instead change the require of D:\@blender\suicideleague\@app\node_modules\react-merge-refs\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

I am using SSR and this is caught on the server side compiling with webpack

@JakobJingleheimer
Copy link
Contributor Author

JakobJingleheimer commented Aug 13, 2022

FYI this merge broke.


Uncaught Error Error [ERR_REQUIRE_ESM]: require() of ES Module D:\@blender\suicideleague\@app\node_modules\react-merge-refs\dist\index.mjs not supported.

Instead change the require of D:\@blender\suicideleague\@app\node_modules\react-merge-refs\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

I am using SSR and this is caught on the server side compiling with webpack

It was an intentional choice of the package owner to break compatibility with CJS. You can follow the error message's suggestion to consume it in CJS.

Please see the release notes of the semver major bump specifically mentioning the breaking change: https://github.com/gregberge/react-merge-refs/releases/tag/v2.0.0

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

Successfully merging this pull request may close these issues.

Package.json does not properly identify its ESM dist as ESM
3 participants