I came into the same problem and after getting frustrated, looking for a solution and not finding one and asking a few friends and stumbled upon a video that kiiiiinda explains it. The guy is speaking in a language I do not understand, but just following along with the visual fixed this problem for me.
Go to your Unity installation folder: Unity/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools and edit the file labeled “emscripten”
Change
NODE_JS=[os.getenv('NODE'),'--stack_size=8192','--max-old-space-size=2048']
to
NODE_JS=[os.getenv('NODE'),'--stack_size=1024','--max-old-space-size=2048']
After doing that, I was able to build my text game no problem. I thought this should be posted here for anyone else who runs into this issue.
Video for reference: https://www.youtube.com/watch?v=lxD02XawLeQ