core: NextFederationPlugin is crashing on bigger project
Hi @ScriptedAlchemy!
Recently we faced an issue with NextFederationPlugin where NextJS/Webpack would crash if we tried to expose all the project pages (~30 pages).
Some observations so far:
- Build does not crash only in build and client-side mode (conditional webpack configuration). I assume it is because the client only is only 50% of memory consumption during the build and fits in standard (4Gb?) nodejs allocation
- Standard memory settings can hold 20 out of 30 pages, although extremely slow
- If I bump memory past 6Gb, it will compile, but dev mode is extremely slow - producing a change is ~15 seconds vs. 1 second without the plugin
- I tried to split up packages into multiple NextFederationPlugin instances, but the outcome is the same (also, it does not support multiple instances?)
- Even with a smaller set of exposed components, eventually, dev mode will run out of memory.
- We use Nextv13, although I installed canary to generate a trace
While clientside and build time only works for the short term, SSR would help determine 404 (if a page is not exposed) and for SEO purposes.
Please find the trace tree attached.
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000
Binaries:
Node: 18.12.1
npm: 8.19.2
Yarn: 1.22.19
pnpm: N/A
Relevant packages:
next: 13.2.5-canary.28
eslint-config-next: 13.2.4
react: 18.2.0
react-dom: 18.2.0
Please advise what should we look into?
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 6
- Comments: 42 (21 by maintainers)
seeing increased memory usage and occasional heap limit reached on build, we only have a handful of components so I don’t think the size is an issue (maybe dependencies, though?)
@ScriptedAlchemy facing the same issue with project of pages ~20 as well. It throws the below
heap memory
error during my build. Interestingly dev server works fine but its notably slow. Currently using nextjs-mf@7.0.6Also after I upgrading to v7.0.6 started seeing this message at the top on dev and build
Any clue?
UPDATE: it has now started crashing in dev server as well after I added couple more pages. Should this be a critical issue?
Hi @ScriptedAlchemy, thanks again for all of your work.
I’m testing the release v6.5.2-rc6.0 and I’m facing a memory issue:
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
when the app is built.Plugin is currently tried locally on our main big app, with ~150 pages (I know it’s crazy). And it seems to be because of the app’s size because there’s no problem with only a few pages built.
I’m happy to bring more details if you want me to try some things in order to have a stable v7.
(edit: same thing with stable release (v7.0.0))
Okay im nearing the stage where i think i can release v7 - however this is a major overhaul so please test it, theres likely to be bugs ill have to hotfix
Increase memory.
Might be resolved when I replace one of the plugins with the data manifest plugin we just shipped but no guarantees.
Not to say that something isnt wrong with my plugin… buuut 150 pages?! Split that with federation!! So theres no build big enough to even worry about memory hahaha. thats impressive size
Really appreciate the help so far @ScriptedAlchemy! Looking forward to testing it.
I have a similar issue. I just posted a related issue about memory issues for a single exposed component. It’s slightly different because my memory consumption is for a single exposed page. But, in my testing, I saw a linear increase in memory as I exposed more pages, and I can only assume that having more exposed pages exacerbates the problem.
I originally exposed multiple pages, but even just trying to build would crash because of out-of-memory errors. Turns out icon libraries would blow the memory past 16gbs for multiple exposed pages. Even without the icons library, I encountered the same memory issues you saw.
Definitely interested in seeing both types of problems resolved.
facing the same issue, In my nextjs project I have around 10 pages, but have 300+ dependencies (actually using components as module hosted on bit.cloud), before I was getting out of memory error, but by increasing heap size to 16192, I’m able to build project locally but it hangs when running on bitbucket pipeline.
I have the same problem. Only able to run the build with
--max-old-space-size
set to16192
otherwise it crashes.The .next folder size is increasing up to 2.5GB when I enable module federation. Without the .next directory is 240 MB
@ScriptedAlchemy .next folder size is increasing up to 7 to 9gb when i apply module federation, any fix for this, please help me on this, if i comment webpack config in next.config.js its taking upto 700 to 900 MB
@ialpert I’m very happy that it’s resolved your longstanding issue. Thank you for your patience
Quick update. I’ve been able to build the app by increasing the Node’s allocated memory with
--max-old-space-size
.It was set to
8192
and now is16192
(which is huge!). Since the app builds successfully without nextjs-mf and since it’s ok with v6, I’d rather not have to do this.I also tried to remove half of the pages of the app, and, without the memory fix, the build fails anyway.
I can provide some logs if I’m told which ones to share.
Actually on second thought I tried to build production and faced the following:
6.4.0 builds just fine
Okay! Thanks for the patience.
I’ve pushed out the first beta release of v7
This contains the contents of the large PR
Note it’s on the “next” tag
https://www.npmjs.com/package/@module-federation/nextjs-mf/v/6.4.1-beta.0
So far, its muuuch better.
The stats plugin still needs work but I’m going to let that roll over to after merge release.
Overall my build times and responsiveness is way better now (like 2x)
Website loads are also much faster now thanks to module hoisting
yes. this next plugin has historically been complicated. its been a huge workaround, i think that rewrite which removes child compiler will simplify things greatly and let us focus on improvements instead of base support.
I do thin in the next major release, im able to remove child compilers which i suspect adds enormous overheads.
heres what i need to generate from stats:
Okay for stats, i need module reasons to track any shared or remote modules. This is not critical but does improve perf when loading code since i can ssr js tags.
I likely dont need that much stats though. So we can most likely trim it down. Take a look at the federation stats json that i emit, thats essentially the info i need to collect, nothing else.