Build container ran out of memory when caching node_modules

Viewed 15

I have a simple React app built with Amplify that has recently started failing with a "out of memory" error.

After a lot of debugging, and outputting free -h at a steady interval the last entry I can see is 1.8GB memory available, and then it starts to cache node_modules as instructed by the amplify.yml file and immediately dies. The amplify.yml file is the default auto-generated one from AWS. It looks like this

amplify.yml

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

My assumption is that the container tries to load the entire contents of node_modules into memory, and save it in an external cache. Of course the node_modules folder is very huge (2.8GB), so the container rapidly consumes memory, and we get the Out Of Memory error

After disabling the last part (caching node_modules) everything works fine, and it never goes below 2GB free memory

Question

Is there any way to cache node_modules without the container running out of memory like this?

0 Answers
Related