'Why is this amplify config causing build failure? Monorepo setup

I have a react project that is setup in a monorepo fashion. I am trying to set up CI/CD triggered by updates to my git repo. The build config that I was using works fine for building the front end, but I can't seem to get the backend to build automatically. What is the correct build config for this type of set up?

My folder structures are these. The /apps/admin folder contains all of the react-app front end stuff. If I do the build manually from my CLI all works fine. I go into /apps/model and run the cli commands there (ex: amplify codegen models and then amplify push)

/ProjectRoot |-- apps |--|-- admin |--|-- model |-- node_modules |-- package.json |-- .gitignore

Initially my build config (which only built the front end successfully) was this:

version: 1
applications:
  - appRoot: apps/admin
    frontend:
      phases:
        preBuild:
          commands:
            - yarn
        build:
          commands:
            - yarn build
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*

So trying to add on to this I attempted to add the backend piece, but this keeps getting me a build fail.

version: 1
applications:
  - appRoot: apps/model
    backend:
      phases:
        preBuild:
          commands:
            - yarn
            - amplify codegen models
        build:
          commands:
            - amplify push -y
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
  - appRoot: apps/admin
    frontend:
      phases:
        preBuild:
          commands:
            - yarn
        build:
          commands:
            - yarn build
      artifacts:
        baseDirectory: build
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*

Excerpt of the log ....

2022-03-14T14:12:29.827Z [INFO]: 
2022-03-14T14:12:29.827Z [INFO]: WARN
2022-03-14T14:12:29.827Z [INFO]: 
2022-03-14T14:12:29.828Z [INFO]: notsup
2022-03-14T14:12:29.828Z [INFO]: SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2022-03-14T14:12:29.875Z [INFO]: npm WARN
2022-03-14T14:12:29.876Z [INFO]: [email protected] requires a peer of graphql@^15.0.0 but none is installed. You must install peer dependencies yourself.
2022-03-14T14:12:29.892Z [INFO]: npm WARN
2022-03-14T14:12:29.893Z [INFO]: @aws-amplify/[email protected] requires a peer of react@^17.0.2 but none is installed. You must install peer dependencies yourself.
2022-03-14T14:12:29.908Z [INFO]: npm WARN
2022-03-14T14:12:29.909Z [INFO]: @aws-amplify/[email protected] requires a peer of react-dom@^17.0.2 but none is installed. You must install peer dependencies yourself.
2022-03-14T14:12:29.918Z [INFO]: npm
2022-03-14T14:12:29.918Z [INFO]: WARN @aws-amplify/[email protected] requires a peer of react@^17.0.2 but none is installed. You must install peer dependencies yourself.
2022-03-14T14:12:29.927Z [INFO]: npm
2022-03-14T14:12:29.927Z [INFO]: WARN @aws-amplify/[email protected] requires a peer of react-dom@^17.0.2 but none is installed. You must install peer dependencies yourself.
2022-03-14T14:12:29.927Z [INFO]: 
2022-03-14T14:12:30.032Z [INFO]: # Done patching NPM package '@aws-amplify/cli' to version 7.6.23
2022-03-14T14:12:30.047Z [INFO]: # Retrieving cache...
2022-03-14T14:12:52.009Z [INFO]: # Extracting cache...
2022-03-14T14:13:11.944Z [INFO]: # Extraction completed
           at Array.forEach (<anonymous>)
                                 at copyDir (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:113:23)
                                 at mkDirAndCopy (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:108:3)
                                 at onDir (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:99:25)
                                 at getStats (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:45:37)
                                 at startCopy (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
                                 at copyDirItem (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:120:10)
                                 at /root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:113:39
                                 at Array.forEach (<anonymous>)
                                 at copyDir (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:113:23)
                                 at mkDirAndCopy (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:108:3)
                                 at onDir (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:99:25)
                                 at getStats (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:45:37)
                                 at startCopy (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
                                 at copyDirItem (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:120:10)
                                 at /root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:113:39
                                 at Array.forEach (<anonymous>)
                                 at copyDir (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:113:23)
                                 at onDir (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:103:10)
                                 at getStats (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:45:37)
                                 at startCopy (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10)
                                 at handleFilterAndCopy (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:33:10)
                                 at Object.copySync (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/fs-extra/lib/copy-sync/copy-sync.js:26:10)
                                 at downloadBackend (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/attach-backend.js:369:8)
                                 at Object.run (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/attach-backend.js:78:3)
                                 at Object.attachBackend (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/index.ts:62:3)
                                 at queryProvider (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/src/attach-backend-steps/a10-queryProvider.ts:12:3)
                                 at attachBackend (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/src/attach-backend.ts:20:5)
                                 at Object.run (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/src/commands/pull.ts:63:5)
                                 at Object.executeAmplifyCommand (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/src/index.ts:373:5)
                                 at executePluginModuleCommand (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/src/execution-manager.ts:178:3)
                                 at executeCommand (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/src/execution-manager.ts:30:5)
                                 at Object.run (/root/.nvm/versions/node/v14.18.1/lib/node_modules/@aws-amplify/cli/src/index.ts:205:5)
2022-03-14T14:13:34.547Z [ERROR]: !!! Build failed
2022-03-14T14:13:34.548Z [ERROR]: !!! Non-Zero Exit Code detected
2022-03-14T14:13:34.548Z [INFO]: # Starting environment caching...
2022-03-14T14:13:34.549Z [INFO]: # Uploading environment cache artifact...
2022-03-14T14:13:34.642Z [INFO]: # Environment caching completed
Terminating logging...


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source