Open rgoldfinger-quizlet opened 2 years ago
It'd be amazing to this fixed, we're blocked on upgrading to next 12+SWC because of this. I'm super happy to attempt a PR if it would be helpful. Still seeing this on 12.0.7
.
Thank you for an amazing project!
Hi, since the reproduction is somewhat obscure, could any of you add a minimal reproduction so that I can investigate, but also test out next@canary
first if it might have been resolved already? Thanks. :pray:
@balazsorban44: Here's a simple reproduction: https://github.com/SirensOfTitan/next-30892
npm run dev
and hit http://localhost:3000/
, notice a blank page and an error related to fs
not being found (in browser context).babelrc.works
to .babelrc
and rerun project, notice that index renders successfully.Is there any update on this? Isomorphic code is a huge plus side of next.js and being unable to fork code in these specific cases creates convoluted code.
Looked at this and it's probably the same as this: https://github.com/vercel/next.js/issues/36514#issuecomment-1112041464.
Had the same issue. Seems like a possible workaround is to refactor code to instead use typeof window !== 'object'
. I think perhaps this might even work with both Terser and SWC, but to be determined.
We are running into this issue with latest Next.js 14/15 with our typeof window !== 'object'
that worked with babel.
What version of Next.js are you using?
12.0.2
What version of Node.js are you using?
16.8.0
What browser are you using?
Chrome / N/A
What operating system are you using?
macOS
How are you deploying your application?
other
Describe the Bug
When using SWC, code wrapped in
if (typeof window === 'undefined')
is not removed from the browser bundle.Without a
.babelrc
in my project (and confirming that it's using SWC via lack ofwarn - Disabled SWC as replacement for Babel
warning), I see that server-side libraries are loaded in the browser bundle.See repro.
Expected Behavior
Code wrapped in
if (typeof window === 'undefined')
is not included in the browser bundle.To Reproduce
Original code:
Browser output using SWC:
Browser output using Babel:
Babel config for reference: