Skip to content

fix CJS & ESM distribution#17

Merged
gregberge merged 1 commit intogregberge:mainfrom
JakobJingleheimer:fix-packagejson-exports
Jan 16, 2022
Merged

fix CJS & ESM distribution#17
gregberge merged 1 commit intogregberge:mainfrom
JakobJingleheimer:fix-packagejson-exports

Conversation

@JakobJingleheimer
Copy link
Copy Markdown
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
@Uniphix
Copy link
Copy Markdown

Uniphix commented Aug 11, 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

@JakobJingleheimer
Copy link
Copy Markdown
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