'AWS codebuild fails stating the error:- COMMAND_EXECUTION_ERROR: Error while executing command: yarn run build. Reason: exit status 1

I am trying to aws codebuild for creating ci/cd pipeline. I have used yarn as package manager. Here is my buildspec file.

# Do not change version. This is the version of aws buildspec, not the version of your buldspec file.
  version: 0.2
  phases:
    install:
      commands:
            - echo update npm...
            - npm install -g n
            - n latest
            - npm update -g npm
            - echo node -v
            - node -v
            - echo npm -v
            - npm -v
            - echo install yarn...
            - npm install -g yarn
            - echo yarn -v
            - yarn -v
    pre_build:
      commands:
        #installs dependencies into the node_modules/ directory
        - echo Entered the pre_build phase...
        - yarn install
    build:
      commands:
        - echo Build started on `date`
        - echo Compiling
        - yarn run build
    post_build:
      commands:
        - echo Build completed on `date`
  # Include only the files required for your application to run.
  artifacts:
    files:
      - public/**/*
      - src/**/*
      - package.json
      - appspec.yml
      - scripts/**/*

PS: Here for some reason by writing only yarn is not working in prebuild phase. But now its showing error in build phase.

COMMAND_EXECUTION_ERROR: Error while executing command: yarn run build. Reason: exit 
 status 1

As I am new to aws I am unable to find solution. Please help me in this if possible. Thank you



Sources

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

Source: Stack Overflow

Solution Source