We are getting intermittent build failure on our React.js application which uses CRA (Create React App).
I was able to capture the error on my local VM.
> node scripts/build.js
Creating an optimized production build...
<--- Last few GCs --->
[136893:0x5232f30] 402726 ms: Scavenge (reduce) 945.2 (981.6) -> 944.7 (981.6) MB, 15.9 / 0.0 ms (average mu = 0.311, current mu = 0.359) allocation failure
[136893:0x5232f30] 402778 ms: Scavenge (reduce) 948.5 (985.4) -> 948.4 (985.4) MB, 25.1 / 0.0 ms (average mu = 0.311, current mu = 0.359) allocation failure
[136893:0x5232f30] 402915 ms: Scavenge (reduce) 952.7 (989.1) -> 952.1 (989.1) MB, 3.8 / 0.0 ms (average mu = 0.311, current mu = 0.359) allocation failure
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xa3ad50 node::Abort() [node]
2: 0x970199 node::FatalError(char const*, char const*) [node]
3: 0xbba90e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xbbac87 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xd76ea5 [node]
6: 0xd77a2f [node]
7: 0xd8586b v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
8: 0xd8942c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
9: 0xd57b0b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
10: 0x10a015f v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
11: 0x1449379 [node]
Aborted (core dumped)
Most of the time, we won't see this error as our Jenkins-X build log will just say that the build process was terminated.
Sometimes, we get OOM error status which gives us a hint that the build process is running out of memory.
I found some similar issue in StackOverflow that leads to the solution:
The fix was to disable generating source map files by setting this to an ENV variable.
GENERATE_SOURCEMAP=false
https://create-react-app.dev/docs/advanced-configuration/
Tested it in my VM and it works!
Note: I am able to consistently replicate the error before trying the fix.
GENERATE_SOURCEMAP=false npm run build
Since we are using Dockerfile to build the static assets, I just added this to Dockerfile
before running npm run build
:
ARG GENERATE_SOURCEMAP=false