Treeshaking problem in pages (Next 12.1.6 and 12.1.7 canary)
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
Binaries:
Node: 14.18.1
npm: 6.14.15
Yarn: 1.19.1
pnpm: N/A
Relevant packages:
next: 12.1.6
react: 18.1.0
react-dom: 18.1.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
We ran into a weird problem in Next 12.1.6 (and latest 12.1.7 canary builds). After updating from an earlier Next version, we noticed that page bundle sizes increased in some cases, without us changing anything else.
Next 12.1.0 (and 12.1.5)
Next 12.1.6 (and 12.1.17 canary)
A bit of research revealed that server-only code was compiled into the bundles. This is likely not the same issue as #16153 as i don’t believe we have server and client code in the same module anywhere with any of it used in the page components themselves (although i can’t rule that out with absolute certainty). In fact, i stripped the page component down to literally just a naked div, without anything else being used, and i still had that server code in the client bundle. And of course it is curious that Next version 12.1.5 and older do not have this problem.
Our app is a SSG/ISR build, we’re using getStaticProps, where all server-specific code is used.
Expected Behavior
No server code compiled into client bundles.
To Reproduce
I tried reproducing the issue in a small create-next-app
-generated app but unfortunately failed, sorry.
I still hope this report is useful for anyone else running into similar issues, or maybe the Next team has ideas what could have caused this.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:7 (4 by maintainers)
Top GitHub Comments
That solves it. Thanks so much for looking into this!
For the record, i had a method getProps in
/pages/resources/index
that i exported and reused in/pages/resources/[slug]
and/pages/resources/search/[[...query]]
. I pulled that method out of the page, and all is well.This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.