aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
188 stars 64 forks source link

Next.js 14 - Build container ran out of memory #1944

Closed jayeshbhole closed 3 months ago

jayeshbhole commented 3 months ago

Environment information

-

Describe the bug

While trying to deploy a Next.js SSR application on amplify, the build container runs out of memory with no relevant logs. This was the last of the logs

# Executing command: NODE_OPTIONS="--max-old-space-size=5632" pnpm run build

2024-09-01T00:17:51.036Z [INFO]: > nitro-interface@0.1.0 build /codebuild/output/src386730432/src/nitro-interface

> next build

2024-09-01T00:17:51.641Z [INFO]: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache

2024-09-01T00:17:51.711Z [INFO]: ▲ Next.js 14.2.3

2024-09-01T00:17:51.711Z [INFO]: - Environments: .env

- Experiments (use with caution):

· turbo

2024-09-01T00:17:51.780Z [INFO]: Creating an optimized production build ...

2024-09-01T00:18:38.415Z [INFO]: ✓ Compiled successfully

2024-09-01T00:18:38.437Z [INFO]: Skipping validation of types

Skipping linting

2024-09-01T00:18:38.871Z [INFO]: Collecting page data ...

2024-09-01T00:18:41.022Z [INFO]: Generating static pages (0/6) ...

2024-09-01T00:18:42.435Z [INFO]: Generating static pages (1/6)

2024-09-01T00:18:42.442Z [INFO]: Generating static pages (2/6)

Generating static pages (4/6)

2024-09-01T00:18:43.271Z [INFO]: ✓ Generating static pages (6/6)

2024-09-01T00:18:43.746Z [INFO]: Finalizing page optimization ...

2024-09-01T00:18:43.747Z [INFO]: Collecting build traces ...

2024-09-01T00:18:59.657Z [INFO]:

Also tried using NODE_OPTIONS="--max-old-space-size=5632"] as mentioned in this issue

Reproduction steps

Following is the amplify.yml file. I've removed next cache as suggested by this troubleshooting guide.

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - export NODE_OPTIONS="--max-old-space-size=5632"
        - npm install -g pnpm
        - pnpm install
    build:
      commands:
        - echo "NEXT_PUBLIC_NITRO_ENV=$NEXT_PUBLIC_NITRO_ENV" >> .env
        - echo "NEXT_PUBLIC_PATHFINDER_API=$NEXT_PUBLIC_PATHFINDER_API" >> .env
        - echo "NEXT_PUBLIC_NITRO_EXPLORER_API=$NEXT_PUBLIC_NITRO_EXPLORER_API" >> .env
        - echo "NEXT_PUBLIC_IS_REFUEL_ENABLED=$NEXT_PUBLIC_IS_REFUEL_ENABLED" >> .env
        - NODE_OPTIONS="--max-old-space-size=5632" pnpm run build
  artifacts:
    baseDirectory: .next
    files:
      - "**/*"
  cache:
    paths:
      - node_modules/**/*

package.json

{
  "name": "interface",
  "version": "0.1.0",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "next build",
    "dev": "next dev",
    "format": "prettier --check src/**/**/*.{ts,tsx,css} --config ./prettier.config.js",
    "format:fix": "prettier --write src/**/**/*.{ts,tsx,css} --config ./prettier.config.js",
    "lint": "next lint",
    "lint:fix": "eslint --fix src/**/*.{ts,tsx,json}",
    "start": "next start"
  },
  "lint-staged": {
    "*.{js,jsx,ts,tsx}": [
      "prettier --write --config ./prettier.config.js"
    ],
    "*.{md,css}": "prettier --write --config ./prettier.config.js"
  },
  "dependencies": {
    "@radix-ui/react-alert-dialog": "^1.0.5",
    "@radix-ui/react-dialog": "^1.0.5",
    "@radix-ui/react-label": "^2.0.2",
    "@radix-ui/react-popover": "^1.1.1",
    "@radix-ui/react-portal": "^1.1.1",
    "@radix-ui/react-progress": "^1.0.3",
    "@radix-ui/react-select": "^2.0.0",
    "@radix-ui/react-separator": "^1.0.3",
    "@radix-ui/react-slot": "^1.0.2",
    "@radix-ui/react-tooltip": "^1.0.7",
    "@t3-oss/env-nextjs": "^0.10.1",
    "@tangled3/react": "^1.4.8",
    "@tanstack/react-query": "^5.44.1",
    "@tanstack/react-query-devtools": "^5.40.1",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.1",
    "cmdk": "^1.0.0",
    "framer-motion": "^11.3.8",
    "geist": "^1.3.0",
    "next": "^14.2.1",
    "next-themes": "^0.3.0",
    "numeral": "^2.0.6",
    "react": "^18.3.0",
    "react-dom": "^18.3.0",
    "sonner": "^1.5.0",
    "tailwind-merge": "^2.3.0",
    "tailwindcss-animate": "^1.0.7",
    "usehooks-ts": "^3.1.0",
    "vaul": "^0.9.1",
    "viem": "^2.18.4",
    "zod": "^3.23.3",
    "zustand": "^4.5.4"
  },
  "devDependencies": {
    "@svgr/webpack": "^8.1.0",
    "@tanstack/eslint-plugin-query": "^5.35.6",
    "@types/eslint": "^8.56.2",
    "@types/node": "^20.11.20",
    "@types/numeral": "^2.0.5",
    "@types/react": "^18.2.57",
    "@types/react-dom": "^18.2.19",
    "@typescript-eslint/eslint-plugin": "^7.1.1",
    "@typescript-eslint/parser": "^7.1.1",
    "eslint": "^8.57.0",
    "eslint-config-next": "^14.1.3",
    "postcss": "^8.4.34",
    "prettier": "^3.2.5",
    "prettier-plugin-tailwindcss": "^0.5.14",
    "tailwindcss": "^3.4.3",
    "typescript": "^5.4.2"
  },
  "ct3aMetadata": {
    "initVersion": "7.34.0"
  },
  "packageManager": "pnpm@9.4.0"
}
jayeshbhole commented 3 months ago

Closing this, fix is to change the pnpm cache path as mentioned in #1919