Skip to content

Amplify Gen 2 React Docs Build Container Out of Memory

0

I'm following the Amplify Gen 2 docs for deploying a Vite + React application. Once I re-deploy the app at the end of Quickstart step 6 (adding login UI), the build fails with the message "Build container ran out of memory" after calling "npm run build" and transforming 1748 modules. The initial build/deployment when following the docs succeeds, but I can't seem to pin down why the second fails. Below are sections from the two build logs (with my account ID and GitHub username omitted) containing only the npm dependency warnings I receive and the statements after "npm run build" is called. Build 1 warnings:

2024-12-05T23:27:38.355Z [WARNING]: npm
2024-12-05T23:27:38.362Z [WARNING]: WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
2024-12-05T23:27:39.031Z [WARNING]: npm WARN
2024-12-05T23:27:39.031Z [WARNING]: deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
2024-12-05T23:27:40.529Z [WARNING]: npm WARN deprecated
2024-12-05T23:27:40.529Z [WARNING]: @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
2024-12-05T23:27:40.605Z [WARNING]: npm WARN
2024-12-05T23:27:40.605Z [WARNING]: deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
2024-12-05T23:27:40.850Z [WARNING]: npm WARN deprecated
2024-12-05T23:27:40.850Z [WARNING]: @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
                                    npm WARN deprecated @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
2024-12-05T23:27:42.156Z [WARNING]: npm WARN
2024-12-05T23:27:42.161Z [WARNING]: deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
2024-12-05T23:27:45.415Z [WARNING]: npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
2024-12-05T23:27:50.306Z [WARNING]: npm WARN
2024-12-05T23:27:50.311Z [WARNING]: deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
2024-12-05T23:27:52.617Z [WARNING]: npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.

Build 1 final statements:

2024-12-05T23:31:15.549Z [INFO]: # Executing command: npm run build
2024-12-05T23:31:15.816Z [INFO]: > amplify-vite-react-template@0.0.0 build
                                 > tsc && vite build
2024-12-05T23:31:21.218Z [INFO]: vite v5.4.10 building for production...
2024-12-05T23:31:21.275Z [INFO]: transforming...
2024-12-05T23:31:23.393Z [INFO]: ✓ 788 modules transformed.
2024-12-05T23:31:23.636Z [INFO]: rendering chunks...
2024-12-05T23:31:23.644Z [INFO]: computing gzip size...
2024-12-05T23:31:23.658Z [INFO]: dist/index.html                   0.46 kB │ gzip:  0.30 kB
2024-12-05T23:31:23.658Z [INFO]: dist/assets/index-BGFuHSfN.css    0.90 kB │ gzip:  0.49 kB
                                 dist/assets/index-CwVTmeDt.js   320.90 kB │ gzip: 99.74 kB
2024-12-05T23:31:23.658Z [INFO]: ✓ built in 2.42s
2024-12-05T23:31:23.682Z [INFO]: # Completed phase: build
                                 ## Completed Frontend Build
2024-12-05T23:31:23.706Z [INFO]: ## Build completed successfully
2024-12-05T23:31:23.707Z [INFO]: # Starting caching...
2024-12-05T23:31:23.711Z [INFO]: # Creating cache artifact...
2024-12-05T23:31:43.395Z [INFO]: # Created cache artifact
2024-12-05T23:31:43.563Z [INFO]: # Uploading cache artifact...
2024-12-05T23:31:53.932Z [INFO]: # Uploaded cache artifact
2024-12-05T23:31:54.115Z [INFO]: # Caching completed
2024-12-05T23:31:54.122Z [INFO]: # Starting build artifact upload process...
2024-12-05T23:31:54.159Z [INFO]: # Uploading build artifact '__artifacts.zip'...
2024-12-05T23:31:54.311Z [INFO]: # Build artifact upload completed
2024-12-05T23:31:54.311Z [INFO]: # Starting environment caching...
2024-12-05T23:31:54.311Z [INFO]: # Uploading environment cache artifact...
2024-12-05T23:31:54.428Z [INFO]: # Uploaded environment cache artifact
2024-12-05T23:31:54.428Z [INFO]: # Environment caching completed

Build 2 warnings:

2024-12-05T23:52:20.197Z [WARNING]: npm
2024-12-05T23:52:20.203Z [WARNING]: WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
2024-12-05T23:52:20.308Z [WARNING]: npm
2024-12-05T23:52:20.309Z [WARNING]: WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
2024-12-05T23:52:20.483Z [WARNING]: npm WARN deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
2024-12-05T23:52:20.544Z [WARNING]: npm
2024-12-05T23:52:20.545Z [WARNING]: WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
2024-12-05T23:52:20.750Z [WARNING]: npm
2024-12-05T23:52:20.751Z [WARNING]: WARN deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
2024-12-05T23:52:20.759Z [WARNING]: npm
2024-12-05T23:52:20.759Z [WARNING]: WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
2024-12-05T23:52:20.789Z [WARNING]: npm
2024-12-05T23:52:20.789Z [WARNING]: WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
2024-12-05T23:52:20.815Z [WARNING]: npm
2024-12-05T23:52:20.815Z [WARNING]: WARN deprecated @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
2024-12-05T23:52:27.476Z [WARNING]: npm WARN
2024-12-05T23:52:27.482Z [WARNING]: deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
2024-12-05T23:52:28.860Z [WARNING]: npm WARN
2024-12-05T23:52:28.860Z [WARNING]: deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.

Build 2 final statements:

# Executing command: npm run build
2024-12-05T23:53:33.983Z [INFO]: > amplify-vite-react-template@0.0.0 build
                                 > tsc && vite build
2024-12-05T23:53:39.588Z [INFO]: vite v5.4.10 building for production...
2024-12-05T23:53:39.641Z [INFO]: transforming...
2024-12-05T23:53:44.137Z [INFO]: ✓ 1748 modules transformed.
<BUILD FAILS HERE>

asked 2 years ago671 views

1 Answer
-1
  1. Increased module count: In the first build, 788 modules were transformed, while in the second build, 1748 modules were transformed. This significant increase in modules is likely contributing to the memory issue.

  2. Build container memory limit: The Amplify build process runs in a container with limited memory. When you added the login UI and related dependencies, the build process may have exceeded the default memory allocation.

To resolve this issue, you can try the following:

  1. Increase build container memory: In the Amplify Console, go to your app's build settings and increase the compute type. Choose a larger instance type with more memory to accommodate the increased build requirements.

  2. Optimize dependencies: Review your project dependencies and remove any unnecessary ones. This can help reduce the number of modules that need to be transformed during the build process.

  3. Use production build flags: Add the --max-old-space-size flag to your build command to allocate more memory to the Node.js process. You can modify your build command in the amplify.yml file:

    build:
      commands:
        - npm run build

    to:

    build:
      commands:
        - node --max-old-space-size=4096 ./node_modules/.bin/vite build

    This allocates 4GB of memory to the build process.

  4. Split your build process: If possible, consider splitting your build process into smaller chunks or using code splitting techniques to reduce the memory requirements of each build step.

  5. Update dependencies: Ensure all your dependencies are up to date, as newer versions may have performance improvements or bug fixes that could help with memory usage.

By implementing these changes, you should be able to resolve the "Build container ran out of memory" error and successfully complete your Amplify Gen 2 React application deployment.

Sources
Deploying a web application using AWS Amplify Gen 2 with GitLab as the Repository on AWS | Front-End Web & Mobile
Quickstart - AWS Amplify Gen 2 Documentation
Troubleshooting - AWS Amplify Gen 2 Documentation

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.