Amplify Console のビルドで「!!!Unable to save headers」というエラーが発生してビルドが失敗した場合の対処方法(モノレポ)

2022.04.25

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

困っていた内容

Amplify Console でビルド中、 !!!Unable to save headersというエラーが発生してビルドが失敗します。カスタムヘッダー関連のエラーと思われますが、対処方法を教えてください。なお、モノレポを使用しています。

どう対応すればいいの??

モノレポ(単一リポジトリで複数プロジェクトを管理)の場合、カスタムヘッダーの YAML 形式が通常と異なります。

For a monorepo, use the following YAML format:

applications:
  - appRoot: app1
    customHeaders:
    - pattern: '**/*'
      headers:
      - key: 'custom-header-name-1'
        value: 'custom-header-value-1'
  - appRoot: app2
    customHeaders:
    - pattern: '/path/*.json'
      headers:
      - key: 'custom-header-name-2'
        value: 'custom-header-value-2'

引用元:Custom header YAML format

customHttp.ymlファイルが上記形式と異なることが原因で、エラーが発生しているかもしれません。
また、その他以下項目が適切でない可能性がありますので、それぞれご確認ください。

  • customHttp.ymlの配置場所
  • Amplify 環境変数AMPLIFY_MONOREPO_APP_ROOTの値(モノレポの設定)


Save the edited customHttp.yml file in your project's root directory. If you are working with a monorepo, save the customHttp.yml file in the root of your repo.
引用元:Setting custom headers


AMPLIFY_MONOREPO_APP_ROOT
The path to use to specify the app root of a monorepo app, relative to the root of your repository.
引用元:Amplify environment variables

参考資料

Custom headers