question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Treeshaking problem in pages (Next 12.1.6 and 12.1.7 canary)

See original GitHub issue

Verify 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) Screen Shot 2022-06-04 at 21 26 23

Next 12.1.6 (and 12.1.17 canary) Screen Shot 2022-06-04 at 21 25 47

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:closed
  • Created a year ago
  • Reactions:4
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
clauscommented, Jun 6, 2022

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.

0reactions
github-actions[bot]commented, Jul 7, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blog - Next.js 12.1
Next.js 12.1 introduces on-demand ISR, support for styled-components and Relay, zero-config Jest support, and more!
Read more >
Eric Bidelman on Twitter: "Webpack/NextJS experts. I have a ...
I have a tree shakeable npm lib used across our app. Some large components only get used on a few pages. Next still...
Read more >
@next/react-dev-overlay: Versions | Openbase
Full version history for @next/react-dev-overlay including change logs. ... Also check error.message as digest for recoverable errors in pages: #44185 ...
Read more >
Reduce JavaScript payloads with tree shaking - web.dev
While this technique works, it doesn't address a common problem of JavaScript-heavy applications, which is the inclusion of code that's never used. Tree...
Read more >
How to enable tree shaking for next.js? - Stack Overflow
I believe the issue with your example is that Next.js is able to tree-shake primitive values (boolean, string, int,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found