CJS + ESM Question/discussion
See original GitHub issueReact Popper pulls in via import isEqual from 'react-fast-compare';
and this is failing in Rollupjs which states default is not exported from [module]
.
Would it be possible for the package that is released to npm contain a cjs
and an esm
file? This would allow for require()
statements as well as import
.
I’ll happily put a PR together if this is desired, but wanted to know where the thoughts were in the project before putting in the effort.
I have this working now using patch-package
with the following patch:
diff --git a/node_modules/react-fast-compare/index.js b/node_modules/react-fast-compare/index.js
index 1301ff0..3fa4874 100644
--- a/node_modules/react-fast-compare/index.js
+++ b/node_modules/react-fast-compare/index.js
@@ -115,7 +115,7 @@ function equal(a, b) {
}
// end fast-deep-equal
-module.exports = function isEqual(a, b) {
+function isEqual(a, b) {
try {
return equal(a, b);
} catch (error) {
@@ -132,3 +132,5 @@ module.exports = function isEqual(a, b) {
throw error;
}
};
+
+export default isEqual;
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
What the heck are CJS, AMD, UMD, and ESM in Javascript?
ESM is the best module format thanks to its simple syntax, async nature, and tree-shakeability. UMD works everywhere and usually used as a ......
Read more >CJS vs ESM - Andrea Giammarchi - Medium
The conclusion, here, is that ESM is a more secure module system than CJS and last, but not least, ESM is about syntax...
Read more >Working with node and only esm packages #7872 - nrwl/nx
Workaround: npm install --save-dev webpack-node-externals; Create webpack.config.cjs in the application directory: // @filename ...
Read more >Publish ESM and CJS in a single package - Anthony Fu
A short tutorial of shipping both ESM and CJS dual formats in a single NPM package.
Read more >What are CJS, AMD, UMD, and ESM in Javascript? - Igor Irianto
What Are CJS, AMD, UMD, and ESM in Javascript? July 21, 2019. In the beginning, Javascript did not have a way to import/export...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can confirm, putting the commonjs plugin before the babel plugin solved this. Not certain why that didn’t work yesterday during my testing, but glad it’s working today… ship it, amiright?
Usually the
commonjs
module in Rollup should be placed pretty early in the pipeline, like afterresolve
, so it may be as simple as that in this case.