🐛 Addresses issue with styled-components and webpack #44
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ℹ️ What is the context for these changes?
Addresses an issue with styled-components and webpack. The problem occurs when styled-components is used inside of an ESM only package that is used within a webpack-based bundler (e.g. CRA + Next.js).
ESM allows for importing in the syntax we're all familiar with. However, the ESM support that Next.js ships with still utilizes
require
instead ofimport
. This means that the compiled styled-components code will look likestyled.default.span
rather thanstyled.span
, which is why you see the error demonstrated in the before section below.There are other approaches to resolving this which I considered, but decided against since they require more lift, such as:
To explain the solution here, what I've effectively done is re-exported styled-components with a "hacky" way of providing backwards-compatible CJS/ESM support. You can read more about this approach here. You can see this implementation here.
🕹️ Demonstration
🎩 How can this be tophatted?
To test this, you will need a Next.js app to test with
dev up && yarn build && cd packages/connect-wallet && yarn link
yarn link "@shopify/connect-wallet"
✅ Checklist
Tested for accessibilityN/AIncludes unit testsN/AUpdated relevant documentation for the changes (if necessary)N/A