Amplify Console Build fails with FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

Amplify console build failure FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory error could occur If application’s node module requires more memory than the default memory limit of node.js

At the writing of this article, Default size of container used by Amplify Console for build is approximately 7 GB.

  1. Fix is to increase the memory limit by adding ‘export NODE_OPTIONS=–max-old-space-size=8192‘ in preBuild configuration.
phases:
    preBuild:
      commands:
        - export NODE_OPTIONS=--max-old-space-size=8192

2. Also, Try setting GENERATE_SOURCEMAP=false in .env file or in Environment Variables.

When set to false, source maps are not generated for a production build. This solves out of memory (OOM) issues on some smaller machines. [1]

For more articles related to Amplify Console check out – https://cloudnamaste.com/category/amplify-console/

References:

[1] https://create-react-app.dev/docs/advanced-configuration/

[2] https://github.com/aws-amplify/amplify-console/issues/1132