prettier: Prettier crashes on formating large files
Hi! I’m working with large ASM.js files generated by Emscripten, when I debug those I use tools like Prettier to make code at lease a little bit more readable.
In case of prettier I’m getting:
<--- Last few GCs --->
[17699:0x2702f10] 20187 ms: Mark-sweep 1397.2 (1424.1) -> 1396.4 (1423.6) MB, 596.2 / 0.0 ms (average mu = 0.145, current mu = 0.011) allocation failure scavenge might not succeed
[17699:0x2702f10] 20833 ms: Mark-sweep 1397.4 (1424.1) -> 1396.7 (1424.1) MB, 643.6 / 0.0 ms (average mu = 0.076, current mu = 0.004) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x2957d235c01d]
1: StubFrame [pc: 0x2957d2313490]
Security context: 0x16bb6979e549 <JSObject>
2: willBreak(aka willBreak) [0xccf8baf92a9] [/home/[moderated]/node_modules/prettier/bin-prettier.js:~9173] [pc=0x2957d2724356](this=0x37817e8826f1 <undefined>,doc=0x0388ed06f201 <Object map = 0x2804a52f5a01>)
3: arguments adaptor frame: 3->1
4: printArgumentsList(aka printArgumentsList) [0xccf8bafbd69...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x8c02c0 node::Abort() [node]
2: 0x8c030c [node]
3: 0xad15de v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xad1814 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xebe752 [node]
6: 0xebe858 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [node]
7: 0xeca982 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
8: 0xecb2b4 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9: 0xecdf21 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
10: 0xe97444 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
11: 0x1136d5e v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
12: 0x2957d235c01d
[1] 17699 abort (core dumped) npx prettier DEF-2515.j
➜ npm --version
6.2.0
➜ node --version
v10.9.0
➜ cat /etc/os-release
NAME=Fedora
VERSION="28 (Workstation Edition)"
ID=fedora
VERSION_ID=28
PLATFORM_ID="platform:f28"
PRETTY_NAME="Fedora 28 (Workstation Edition)"
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 12
- Comments: 17 (5 by maintainers)
allocations.json is 137MB. I tried he NODE_OPTIONS environment variable that @trzecieu mentioned:
Node memory peaked at 16.42 GB, then crashed:
Anything larger gave me a
Any other workaround suggestions are welcome.
@suchipi Thanks a lot. That actually worked for me:
@mkreim You might find success by leveraging the NODE_OPTIONS environment variable that @trzecieu mentioned
Can be reproduced with Unity’s demo of ASM.js
This works for me:
pnpm dlx prettier --write YOUR_BIG_FILE_PATH
For a passable alternative, BeatifulSoup’s
prettify()
succeeds where Prettier runs out of memory or ends up with call stack exceeded.It looks like your computer might be running out of memory- see this line:
I’m not saying we couldn’t improve this, but as a workaround, you could try formatting the file on a box with more memory.