-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 ESM bundle relying on named imports from react-is #3367
Conversation
@probablyup Is it worth it to finally drop There's one section for development warning purposes that isn't effective anymore, i.e. it looks flawed since it checks for an element ( styled-components/packages/styled-components/src/utils/flatten.js Lines 70 to 77 in a808f40
The other usage checks for the input type to styled-components/packages/styled-components/src/constructors/constructWithOptions.js Lines 14 to 16 in 72a6f64
It may be effective in theory since we're trying to include |
@@ -28,7 +28,44 @@ const esm = { | |||
const getCJS = override => ({ ...cjs, ...override }); | |||
const getESM = override => ({ ...esm, ...override }); | |||
|
|||
/** | |||
* Support external dependencies on CommonJS modules without relying on named export inference | |||
* (works similarly to more recent versions of Rollup's commonjs plugin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- (works similarly to more recent versions of Rollup's commonjs plugin)
Should we just update the CJS plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could, but that would require updating Rollup 2 major versions forward, which is a pretty major change (everything broke when I tried).
Dropped this dep in 8165cbe :) |
This PR fix
styled-components
' ESM bundles so that they don't rely on named importsreact-is
.From a correctness standpoint, it's generally best to avoid relying on named export inference.
More importantly though,
react-is
doesn't support inference because it conditionally definesmodule.exports
based on build-time constants.The solution I've implemented in this PR is essentially applying the recommendation from #3256 (passing
namedExports
to the commonjs plugin). The difference is that it is applied to the styled-components bundles themselves, rather than requiring everyone include the workaround in their own config.With this change, the ESM bundles now import
react-is
in a way that works in environments with even the most basic CommonJS-ESM interop:Fixes #3366.