-
Notifications
You must be signed in to change notification settings - Fork 27.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
NextJS 13 unused client component increases First Load JS size (tree shaking not working for client component) #49742
Comments
I've been digging into a similar issue and it seems that on your example, adding const nextConfig = {
modularizeImports: {
'./components': {
transform: './components/{{member}}',
skipDefaultConversion: true,
}
}
} I uncommented the export in |
Hi @roch-numbered , thank you for the solution. Yes, in fact, I have 50 lines of modularizeImports for now to walk around this issue and also as 13.1 suggested to improve the fast reload speed, but just thought the tree shaking should be default without the need of using modularizeImports. |
To be honest, was also expecting tree shaking to work out of the box. Good to have a way to configure it, but still... |
This seems to be now superseded by |
From the docs, it sounds like it's not even supposed to... We're being fed with self-praising posts about huge bundle size reductions but the reality is that The regression with barrel files happened in version 13, a year ago! |
@Antonio-Laguna is there for fixing the bug: #59254. However, it's generally better to not put |
@shuding I wasn't using |
Also it's necessary to note here that this bug is very different (and not related to) our bundling improvements of barrel and other optimizations. The bug here is specifically related to client boundaries (
|
@Antonio-Laguna Thanks for the quick reply! I see, it sounds like then it's not related to We'll prioritize this issue in the meantime 🙏 |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 Binaries: Node: 18.15.0 npm: 9.5.0 Yarn: 1.22.19 pnpm: N/A Relevant packages: next: 13.4.2 eslint-config-next: 13.3.0 react: 18.2.0 react-dom: 18.2.0 typescript: 4.9.5
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://github.com/TrustyTechSG/tree-shaking
To Reproduce
File structure as below:
app/components/ComponenA.js
app/components/ComponentB.js (is client component "use client")
app/components/index.js
app/page.js
app/layout.js
components/index.js re-export ComponentA and ComponentB.
Only use componentA in page.js
import { ComponentA } from "./components";
Describe the Bug
ComponentB is not used, but it still increases First load JS size.
Before add ComponentB
After add export * from "./ComponentB" to app/components/index.js
Expected Behavior
Tree shaking ComponentB, it should not effect the First load JS size.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
NEXT-1799
The text was updated successfully, but these errors were encountered: