You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when trying to use react-responsive in an ESM context (or through an intermediate library that has both CJS and ESM outputs), the default import in ESM is not the MediaQuery component, rather it's an object with a default property.
Workaround - provide a named export of MediaQuery in addition to the default export. Folks running into this could then use the named imports instead of default import. named imports have better compatibility in CJS and ESM. This is the easiest option & I will file a PR for this soon. But it is also more of a workaround and not a complete solution.
Do a breaking change that replaces the default export with a named export, to ensure more compatibility with both CJS and ESM.
The text was updated successfully, but these errors were encountered:
Okay, seems that maybe there isn't actually an issue with this library, I seem to have run into webpack/webpack#16125... in any case, using named exports/imports does work around such issues, so perhaps moving that way would still make sense?
Currently, when trying to use react-responsive in an ESM context (or through an intermediate library that has both CJS and ESM outputs), the default import in ESM is not the MediaQuery component, rather it's an object with a default property.
Reproduction
See https://github.com/mihkeleidast/react-responsive-esm-demo
Steps:
2, Run node test.js, see that
[Function: MediaQuery]
is logged to console (this is CJS usage)Context
I am trying to build an intermediate library that uses react-responsive, has both ESM and CJS outputs so it could be used in both contexts.
Rollup part of this is documented here, but does not seem to have any traction: rollup/rollup#5265
See also the TypeScript documentation about this problem: https://www.typescriptlang.org/docs/handbook/modules/appendices/esm-cjs-interop.html#library-code-needs-special-considerations
Solutions
The text was updated successfully, but these errors were encountered: