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)

Most upvoted comments

allocations.json is 137MB. I tried he NODE_OPTIONS environment variable that @trzecieu mentioned:

NODE_OPTIONS=--max_old_space_size=16384 prettier  --write  ./allocations.json

Node memory peaked at 16.42 GB, then crashed:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Anything larger gave me a

RangeError: Set maximum size exceeded

Any other workaround suggestions are welcome.

@suchipi Thanks a lot. That actually worked for me:

$ /usr/bin/time --verbose yarn spsprettier
yarn run v1.12.3
$ NODE_OPTIONS=--max_old_space_size=4096 prettier --single-quote --trailing-comma es5 --print-width 100 --write src/spsSampleData_2.js
src/spsSampleData_2.js 26485ms
Done in 27.00s.
        Command being timed: "yarn spsprettier"
        User time (seconds): 41.90
        System time (seconds): 2.03
        Percent of CPU this job got: 161%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:27.22
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 2966620
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 848333
        Voluntary context switches: 51786
        Involuntary context switches: 6432
        Swaps: 0
        File system inputs: 0
        File system outputs: 16
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

@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

wget https://files.unity3d.com/jonas/AngryBots/Release/AngryBots.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:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

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.