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
@emotion/react pulls babel into production builds on node 16/npm 8 #2588
Comments
How is that so? Even if this gets installed it will only grow your
I understand your frustration but I don't fully agree that this is an issue with Emotion. The package is clearly stated as optional peer dependency - they shouldn't be installing it in the first place. AFAIK other package managers have raised concerns that how npm auto-installs peer deps is harmful. I don't know the full context behind their words but I believe there is a strong reason why other package managers don't do this. So from my PoV, this really looks like a problem with npm itself and not with Emotion. |
Yep, sorry about the bundle size thing, you're right. What i'm wondering right now is why this artifact declares babel as a peer dependency at all. I can totally see this for While i share your opinion that the recent change in Node is not for the better and quite contra-intuitive when it comes to optional dependencies, i would still propose having a thought about some mitigation here: Node releases a new LTS every 1,5 years or so, so even if this behaviour will change, it will be around for quite some time and we as a community will somehow have to cope with it. |
It's because we export a Babel macro here: https://github.com/emotion-js/emotion/blob/01cca604ca93c5fd3958c41045ecbcac72b65480/packages/react/macro.js . And with such package structure we have to declare optional peer dependency for Babel as without it this wouldn't work at all with strict package managers like pnpm or Yarn Berry |
These packages don't seem to be specifying |
You are right that this wasn't declared properly by |
Thanks! But I wonder if |
It kinda should but this was deliberately chosen as a solution for its simplicity (you don't have to manually install
While this would be technically possible and correct - it would look kinda weird for consumers so this is probably not something that we'd like to do. In most situations, macros are part of the package (or are the package) - we just reuse the logic for both macros and the Babel plugin so we import this instead of reimplementing stuff or spreading the Babel-related implementation details across packages. |
Closing in favor of #2660 since both issues are really about the same thing. |
Current behavior:
@emotion/react
has an optional peer dependency on@babel/core
.Node 14 LTS included NPM 6, which issued warnings on missing peer dependencies. Node 16 recently became LTS and it now includes NPM 8, which automatically installs peer dependencies. This behaviour can only be circumvented by enabling a
--legacy-peer-deps
flag, which - judging by it's name - is deprecated by design.So, from Node 16 on, a production dependency on
@emotion/react
will automatically pull@babel/core
into your production build.Why is this bad?
@babel/core
depends on other packages likecaniuse-lite
which is licensed unterCC-BY-4.0
which triggers probably unexpected legal attribution requirements when being shipped as part of a React App.To reproduce:
package.json
with@emotion/react
as a production dependencynpm i --production
in a node 14 environmentnpm ls caniuse-lite -prod
will show no entrynpm i --production
npm ls caniuse-lite -prod
will showExpected behavior:
Installing
@emotion/react
should not pull babel into your production buildEnvironment information:
@emotion/react@11.6.0
node v16.13.1
npm 8.1.2
The text was updated successfully, but these errors were encountered: